2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4 * Copyright (C) 2010-2011 Google Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "JSInjectedScriptHost.h"
41 #include "JSDatabase.h"
43 #include "ExceptionCode.h"
44 #include "InjectedScriptHost.h"
45 #include "InspectorDebuggerAgent.h"
46 #include "InspectorValues.h"
47 #include "JSHTMLAllCollection.h"
48 #include "JSHTMLCollection.h"
50 #include "JSNodeList.h"
51 #include "ScriptValue.h"
52 #if ENABLE(DOM_STORAGE)
54 #include "JSStorage.h"
56 #include <runtime/DateInstance.h>
57 #include <runtime/Error.h>
58 #include <runtime/JSArray.h>
59 #include <runtime/JSFunction.h>
60 #include <runtime/JSLock.h>
61 #include <runtime/RegExpObject.h>
67 Node* InjectedScriptHost::scriptValueAsNode(ScriptValue value)
69 if (!value.isObject() || value.isNull())
71 return toNode(value.jsValue());
74 ScriptValue InjectedScriptHost::nodeAsScriptValue(ScriptState* state, Node* node)
76 JSLock lock(SilenceAssertionsOnly);
77 return ScriptValue(state->globalData(), toJS(state, deprecatedGlobalObjectForPrototype(state), node));
80 JSValue JSInjectedScriptHost::evaluate(ExecState* exec)
82 JSValue expression = exec->argument(0);
83 if (!expression.isString())
84 return throwError(exec, createError(exec, "String argument expected."));
85 JSGlobalObject* globalObject = exec->lexicalGlobalObject();
86 JSFunction* evalFunction = globalObject->evalFunction();
88 CallType callType = evalFunction->getCallData(callData);
89 if (callType == CallTypeNone)
91 MarkedArgumentBuffer args;
92 args.append(expression);
94 bool wasEvalEnabled = globalObject->evalEnabled();
95 globalObject->setEvalEnabled(true);
96 JSValue result = JSC::call(exec, evalFunction, callType, callData, exec->globalThisValue(), args);
97 globalObject->setEvalEnabled(wasEvalEnabled);
102 JSValue JSInjectedScriptHost::inspectedNode(ExecState* exec)
104 if (exec->argumentCount() < 1)
105 return jsUndefined();
107 Node* node = impl()->inspectedNode(exec->argument(0).toInt32(exec));
109 return jsUndefined();
111 JSLock lock(SilenceAssertionsOnly);
112 return toJS(exec, globalObject(), node);
115 JSValue JSInjectedScriptHost::internalConstructorName(ExecState* exec)
117 if (exec->argumentCount() < 1)
118 return jsUndefined();
120 UString result = exec->argument(0).toThisObject(exec)->className();
121 return jsString(exec, result);
124 JSValue JSInjectedScriptHost::isHTMLAllCollection(ExecState* exec)
126 if (exec->argumentCount() < 1)
127 return jsUndefined();
129 JSValue value = exec->argument(0);
130 return jsBoolean(value.inherits(&JSHTMLAllCollection::s_info));
133 JSValue JSInjectedScriptHost::type(ExecState* exec)
135 if (exec->argumentCount() < 1)
136 return jsUndefined();
138 JSValue value = exec->argument(0);
139 if (value.isString())
140 return jsString(exec, String("string"));
141 if (value.inherits(&JSArray::s_info))
142 return jsString(exec, String("array"));
143 if (value.isBoolean())
144 return jsString(exec, String("boolean"));
145 if (value.isNumber())
146 return jsString(exec, String("number"));
147 if (value.inherits(&DateInstance::s_info))
148 return jsString(exec, String("date"));
149 if (value.inherits(&RegExpObject::s_info))
150 return jsString(exec, String("regexp"));
151 if (value.inherits(&JSNode::s_info))
152 return jsString(exec, String("node"));
153 if (value.inherits(&JSNodeList::s_info))
154 return jsString(exec, String("array"));
155 if (value.inherits(&JSHTMLCollection::s_info))
156 return jsString(exec, String("array"));
157 return jsUndefined();
160 JSValue JSInjectedScriptHost::inspect(ExecState* exec)
162 if (exec->argumentCount() >= 2) {
163 ScriptValue object(exec->globalData(), exec->argument(0));
164 ScriptValue hints(exec->globalData(), exec->argument(1));
165 impl()->inspectImpl(object.toInspectorValue(exec), hints.toInspectorValue(exec));
167 return jsUndefined();
170 JSValue JSInjectedScriptHost::databaseId(ExecState* exec)
172 if (exec->argumentCount() < 1)
173 return jsUndefined();
175 Database* database = toDatabase(exec->argument(0));
177 return jsNumber(impl()->databaseIdImpl(database));
179 return jsUndefined();
182 JSValue JSInjectedScriptHost::storageId(ExecState* exec)
184 if (exec->argumentCount() < 1)
185 return jsUndefined();
186 #if ENABLE(DOM_STORAGE)
187 Storage* storage = toStorage(exec->argument(0));
189 return jsNumber(impl()->storageIdImpl(storage));
191 return jsUndefined();
194 } // namespace WebCore
196 #endif // ENABLE(INSPECTOR)