diff options
Diffstat (limited to 'Source/WebCore/bindings/js/JSCommandLineAPIHostCustom.cpp')
-rw-r--r-- | Source/WebCore/bindings/js/JSCommandLineAPIHostCustom.cpp | 100 |
1 files changed, 45 insertions, 55 deletions
diff --git a/Source/WebCore/bindings/js/JSCommandLineAPIHostCustom.cpp b/Source/WebCore/bindings/js/JSCommandLineAPIHostCustom.cpp index be0ae27f3..d89b305be 100644 --- a/Source/WebCore/bindings/js/JSCommandLineAPIHostCustom.cpp +++ b/Source/WebCore/bindings/js/JSCommandLineAPIHostCustom.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007-2008, 2016 Apple Inc. All rights reserved. * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> * Copyright (C) 2010-2011 Google Inc. All rights reserved. * @@ -31,13 +31,12 @@ */ #include "config.h" - -#if ENABLE(INSPECTOR) - #include "JSCommandLineAPIHost.h" #include "CommandLineAPIHost.h" +#include "Database.h" #include "InspectorDOMAgent.h" +#include "JSDatabase.h" #include "JSEventListener.h" #include "JSNode.h" #include "JSStorage.h" @@ -45,129 +44,120 @@ #include <bindings/ScriptValue.h> #include <inspector/InspectorValues.h> #include <parser/SourceCode.h> +#include <runtime/IdentifierInlines.h> #include <runtime/JSArray.h> #include <runtime/JSFunction.h> #include <runtime/JSLock.h> #include <runtime/ObjectConstructor.h> -#if ENABLE(SQL_DATABASE) -#include "Database.h" -#include "JSDatabase.h" -#endif - using namespace JSC; namespace WebCore { -JSValue JSCommandLineAPIHost::inspectedObject(ExecState* exec) +JSValue JSCommandLineAPIHost::inspectedObject(ExecState& state) { - if (exec->argumentCount() < 1) - return jsUndefined(); - - CommandLineAPIHost::InspectableObject* object = impl().inspectedObject(exec->uncheckedArgument(0).toInt32(exec)); + CommandLineAPIHost::InspectableObject* object = wrapped().inspectedObject(); if (!object) return jsUndefined(); - JSLockHolder lock(exec); - Deprecated::ScriptValue scriptValue = object->get(exec); - if (scriptValue.hasNoValue()) - return jsUndefined(); - - return scriptValue.jsValue(); + JSLockHolder lock(&state); + auto scriptValue = object->get(state); + return scriptValue ? scriptValue : jsUndefined(); } -static JSArray* getJSListenerFunctions(ExecState* exec, Document* document, const EventListenerInfo& listenerInfo) +static JSArray* getJSListenerFunctions(ExecState& state, Document* document, const EventListenerInfo& listenerInfo) { - JSArray* result = constructEmptyArray(exec, nullptr); + VM& vm = state.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + JSArray* result = constructEmptyArray(&state, nullptr); + RETURN_IF_EXCEPTION(scope, nullptr); size_t handlersCount = listenerInfo.eventListenerVector.size(); for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { - const JSEventListener* jsListener = JSEventListener::cast(listenerInfo.eventListenerVector[i].listener.get()); + const JSEventListener* jsListener = JSEventListener::cast(&listenerInfo.eventListenerVector[i]->callback()); if (!jsListener) { ASSERT_NOT_REACHED(); continue; } // Hide listeners from other contexts. - if (&jsListener->isolatedWorld() != ¤tWorld(exec)) + if (&jsListener->isolatedWorld() != ¤tWorld(&state)) continue; JSObject* function = jsListener->jsFunction(document); if (!function) continue; - JSObject* listenerEntry = constructEmptyObject(exec); - listenerEntry->putDirect(exec->vm(), Identifier(exec, "listener"), function); - listenerEntry->putDirect(exec->vm(), Identifier(exec, "useCapture"), jsBoolean(listenerInfo.eventListenerVector[i].useCapture)); - result->putDirectIndex(exec, outputIndex++, JSValue(listenerEntry)); + JSObject* listenerEntry = constructEmptyObject(&state); + listenerEntry->putDirect(vm, Identifier::fromString(&state, "listener"), function); + listenerEntry->putDirect(vm, Identifier::fromString(&state, "useCapture"), jsBoolean(listenerInfo.eventListenerVector[i]->useCapture())); + result->putDirectIndex(&state, outputIndex++, JSValue(listenerEntry)); + RETURN_IF_EXCEPTION(scope, nullptr); } return result; } -JSValue JSCommandLineAPIHost::getEventListeners(ExecState* exec) +JSValue JSCommandLineAPIHost::getEventListeners(ExecState& state) { - if (exec->argumentCount() < 1) + if (state.argumentCount() < 1) return jsUndefined(); - JSValue value = exec->uncheckedArgument(0); + VM& vm = state.vm(); + JSValue value = state.uncheckedArgument(0); if (!value.isObject() || value.isNull()) return jsUndefined(); - Node* node = toNode(value); + Node* node = JSNode::toWrapped(vm, value); if (!node) return jsUndefined(); Vector<EventListenerInfo> listenersArray; - impl().getEventListenersImpl(node, listenersArray); + wrapped().getEventListenersImpl(node, listenersArray); - JSObject* result = constructEmptyObject(exec); + JSObject* result = constructEmptyObject(&state); for (size_t i = 0; i < listenersArray.size(); ++i) { - JSArray* listeners = getJSListenerFunctions(exec, &node->document(), listenersArray[i]); + JSArray* listeners = getJSListenerFunctions(state, &node->document(), listenersArray[i]); if (!listeners->length()) continue; AtomicString eventType = listenersArray[i].eventType; - result->putDirect(exec->vm(), Identifier(exec, eventType.impl()), JSValue(listeners)); + result->putDirect(state.vm(), Identifier::fromString(&state, eventType.impl()), JSValue(listeners)); } return result; } -JSValue JSCommandLineAPIHost::inspect(ExecState* exec) +JSValue JSCommandLineAPIHost::inspect(ExecState& state) { - if (exec->argumentCount() >= 2) { - Deprecated::ScriptValue object(exec->vm(), exec->uncheckedArgument(0)); - Deprecated::ScriptValue hints(exec->vm(), exec->uncheckedArgument(1)); - impl().inspectImpl(object.toInspectorValue(exec), hints.toInspectorValue(exec)); - } - + if (state.argumentCount() < 2) + return jsUndefined(); + wrapped().inspectImpl(Inspector::toInspectorValue(state, state.uncheckedArgument(0)), + Inspector::toInspectorValue(state, state.uncheckedArgument(1))); return jsUndefined(); } -JSValue JSCommandLineAPIHost::databaseId(ExecState* exec) +JSValue JSCommandLineAPIHost::databaseId(ExecState& state) { - if (exec->argumentCount() < 1) + if (state.argumentCount() < 1) return jsUndefined(); -#if ENABLE(SQL_DATABASE) - Database* database = toDatabase(exec->uncheckedArgument(0)); + VM& vm = state.vm(); + Database* database = JSDatabase::toWrapped(vm, state.uncheckedArgument(0)); if (database) - return jsStringWithCache(exec, impl().databaseIdImpl(database)); -#endif + return jsStringWithCache(&state, wrapped().databaseIdImpl(database)); return jsUndefined(); } -JSValue JSCommandLineAPIHost::storageId(ExecState* exec) +JSValue JSCommandLineAPIHost::storageId(ExecState& state) { - if (exec->argumentCount() < 1) + if (state.argumentCount() < 1) return jsUndefined(); - Storage* storage = toStorage(exec->uncheckedArgument(0)); + VM& vm = state.vm(); + Storage* storage = JSStorage::toWrapped(vm, state.uncheckedArgument(0)); if (storage) - return jsStringWithCache(exec, impl().storageIdImpl(storage)); + return jsStringWithCache(&state, wrapped().storageIdImpl(storage)); return jsUndefined(); } } // namespace WebCore - -#endif // ENABLE(INSPECTOR) |