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.
34 #include "JSInjectedScriptHost.h"
40 #include "JSDatabase.h"
42 #include "ExceptionCode.h"
43 #include "InjectedScriptHost.h"
44 #include "InspectorDebuggerAgent.h"
45 #include "InspectorValues.h"
47 #include "ScriptValue.h"
48 #if ENABLE(DOM_STORAGE)
50 #include "JSStorage.h"
52 #include <runtime/JSLock.h>
54 #if ENABLE(JAVASCRIPT_DEBUGGER)
55 #include "JavaScriptCallFrame.h"
56 #include "JSJavaScriptCallFrame.h"
57 #include "ScriptDebugServer.h"
64 Node* InjectedScriptHost::scriptValueAsNode(ScriptValue value)
66 if (!value.isObject() || value.isNull())
68 return toNode(value.jsValue());
71 ScriptValue InjectedScriptHost::nodeAsScriptValue(ScriptState* state, Node* node)
73 JSLock lock(SilenceAssertionsOnly);
74 return ScriptValue(state->globalData(), toJS(state, node));
77 JSValue JSInjectedScriptHost::currentCallFrame(ExecState* exec)
79 #if ENABLE(JAVASCRIPT_DEBUGGER)
80 JavaScriptCallFrame* callFrame = impl()->debuggerAgent()->scriptDebugServer().currentCallFrame();
81 if (!callFrame || !callFrame->isValid())
84 JSLock lock(SilenceAssertionsOnly);
85 return toJS(exec, callFrame);
92 JSValue JSInjectedScriptHost::inspectedNode(ExecState* exec)
94 if (exec->argumentCount() < 1)
97 Node* node = impl()->inspectedNode(exec->argument(0).toInt32(exec));
101 JSLock lock(SilenceAssertionsOnly);
102 return toJS(exec, node);
105 JSValue JSInjectedScriptHost::internalConstructorName(ExecState* exec)
107 if (exec->argumentCount() < 1)
108 return jsUndefined();
110 UString result = exec->argument(0).toThisObject(exec)->className();
111 return jsString(exec, result);
114 JSValue JSInjectedScriptHost::inspect(ExecState* exec)
116 if (exec->argumentCount() >= 2) {
117 ScriptValue object(exec->globalData(), exec->argument(0));
118 ScriptValue hints(exec->globalData(), exec->argument(1));
119 impl()->inspectImpl(object.toInspectorValue(exec), hints.toInspectorValue(exec));
121 return jsUndefined();
124 JSValue JSInjectedScriptHost::databaseId(ExecState* exec)
126 if (exec->argumentCount() < 1)
127 return jsUndefined();
129 Database* database = toDatabase(exec->argument(0));
131 return jsNumber(impl()->databaseIdImpl(database));
133 return jsUndefined();
136 JSValue JSInjectedScriptHost::storageId(ExecState* exec)
138 if (exec->argumentCount() < 1)
139 return jsUndefined();
140 #if ENABLE(DOM_STORAGE)
141 Storage* storage = toStorage(exec->argument(0));
143 return jsNumber(impl()->storageIdImpl(storage));
145 return jsUndefined();
148 } // namespace WebCore
150 #endif // ENABLE(INSPECTOR)