diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp')
-rw-r--r-- | Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp | 148 |
1 files changed, 86 insertions, 62 deletions
diff --git a/Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp b/Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp index 08fd618a8..1916c5dc8 100644 --- a/Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp +++ b/Source/JavaScriptCore/inspector/JSJavaScriptCallFrame.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Apple Inc. All rights reserved. + * Copyright (C) 2014, 2016 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,30 +26,29 @@ #include "config.h" #include "JSJavaScriptCallFrame.h" -#if ENABLE(INSPECTOR) - +#include "DebuggerScope.h" #include "Error.h" -#include "JSCJSValue.h" -#include "JSCellInlines.h" +#include "IdentifierInlines.h" +#include "JSCInlines.h" #include "JSJavaScriptCallFramePrototype.h" -#include "StructureInlines.h" +#include "ObjectConstructor.h" using namespace JSC; namespace Inspector { -const ClassInfo JSJavaScriptCallFrame::s_info = { "JavaScriptCallFrame", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSJavaScriptCallFrame) }; +const ClassInfo JSJavaScriptCallFrame::s_info = { "JavaScriptCallFrame", &Base::s_info, 0, CREATE_METHOD_TABLE(JSJavaScriptCallFrame) }; -JSJavaScriptCallFrame::JSJavaScriptCallFrame(VM& vm, Structure* structure, PassRefPtr<JavaScriptCallFrame> impl) +JSJavaScriptCallFrame::JSJavaScriptCallFrame(VM& vm, Structure* structure, Ref<JavaScriptCallFrame>&& impl) : JSDestructibleObject(vm, structure) - , m_impl(impl.leakRef()) + , m_impl(&impl.leakRef()) { } void JSJavaScriptCallFrame::finishCreation(VM& vm) { Base::finishCreation(vm); - ASSERT(inherits(info())); + ASSERT(inherits(vm, info())); } JSObject* JSJavaScriptCallFrame::createPrototype(VM& vm, JSGlobalObject* globalObject) @@ -65,10 +64,8 @@ void JSJavaScriptCallFrame::destroy(JSC::JSCell* cell) void JSJavaScriptCallFrame::releaseImpl() { - if (m_impl) { - m_impl->deref(); - m_impl = nullptr; - } + if (auto impl = std::exchange(m_impl, nullptr)) + impl->deref(); } JSJavaScriptCallFrame::~JSJavaScriptCallFrame() @@ -76,55 +73,83 @@ JSJavaScriptCallFrame::~JSJavaScriptCallFrame() releaseImpl(); } -JSValue JSJavaScriptCallFrame::evaluate(ExecState* exec) +JSValue JSJavaScriptCallFrame::evaluateWithScopeExtension(ExecState* exec) { - JSValue exception; - JSValue result = impl().evaluate(exec->argument(0).toString(exec)->value(exec), exception); + VM& vm = exec->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + JSValue scriptValue = exec->argument(0); + if (!scriptValue.isString()) + return throwTypeError(exec, scope, ASCIILiteral("JSJavaScriptCallFrame.evaluateWithScopeExtension first argument must be a string.")); + + String script = asString(scriptValue)->value(exec); + RETURN_IF_EXCEPTION(scope, JSValue()); + + NakedPtr<Exception> exception; + JSObject* scopeExtension = exec->argument(1).getObject(); + JSValue result = impl().evaluateWithScopeExtension(script, scopeExtension, exception); if (exception) - exec->vm().throwException(exec, exception); + throwException(exec, scope, exception); return result; } -JSValue JSJavaScriptCallFrame::scopeType(ExecState* exec) +static JSValue valueForScopeType(DebuggerScope* scope) { - if (!impl().scopeChain()) - return jsUndefined(); + if (scope->isCatchScope()) + return jsNumber(JSJavaScriptCallFrame::CATCH_SCOPE); + if (scope->isFunctionNameScope()) + return jsNumber(JSJavaScriptCallFrame::FUNCTION_NAME_SCOPE); + if (scope->isWithScope()) + return jsNumber(JSJavaScriptCallFrame::WITH_SCOPE); + if (scope->isNestedLexicalScope()) + return jsNumber(JSJavaScriptCallFrame::NESTED_LEXICAL_SCOPE); + if (scope->isGlobalLexicalEnvironment()) + return jsNumber(JSJavaScriptCallFrame::GLOBAL_LEXICAL_ENVIRONMENT_SCOPE); + if (scope->isGlobalScope()) + return jsNumber(JSJavaScriptCallFrame::GLOBAL_SCOPE); - if (!exec->argument(0).isInt32()) + ASSERT(scope->isClosureScope()); + return jsNumber(JSJavaScriptCallFrame::CLOSURE_SCOPE); +} + +static JSValue valueForScopeLocation(ExecState* exec, const DebuggerLocation& location) +{ + if (location.sourceID == noSourceID) + return jsNull(); + + // Debugger.Location protocol object. + JSObject* result = constructEmptyObject(exec); + result->putDirect(exec->vm(), Identifier::fromString(exec, "scriptId"), jsString(exec, String::number(location.sourceID))); + result->putDirect(exec->vm(), Identifier::fromString(exec, "lineNumber"), jsNumber(location.line)); + result->putDirect(exec->vm(), Identifier::fromString(exec, "columnNumber"), jsNumber(location.column)); + return result; +} + +JSValue JSJavaScriptCallFrame::scopeDescriptions(ExecState* exec) +{ + VM& vm = exec->vm(); + auto throwScope = DECLARE_THROW_SCOPE(vm); + + DebuggerScope* scopeChain = impl().scopeChain(); + if (!scopeChain) return jsUndefined(); - int index = exec->argument(0).asInt32(); - - JSScope* scopeChain = impl().scopeChain(); - ScopeChainIterator end = scopeChain->end(); - - // FIXME: We should be identifying and returning CATCH_SCOPE appropriately. - - bool foundLocalScope = false; - for (ScopeChainIterator iter = scopeChain->begin(); iter != end; ++iter) { - JSObject* scope = iter.get(); - if (scope->isActivationObject()) { - if (!foundLocalScope) { - // First activation object is local scope, each successive activation object is closure. - if (!index) - return jsNumber(JSJavaScriptCallFrame::LOCAL_SCOPE); - foundLocalScope = true; - } else if (!index) - return jsNumber(JSJavaScriptCallFrame::CLOSURE_SCOPE); - } - - if (!index) { - // Last in the chain is global scope. - if (++iter == end) - return jsNumber(JSJavaScriptCallFrame::GLOBAL_SCOPE); - return jsNumber(JSJavaScriptCallFrame::WITH_SCOPE); - } - - --index; + + int index = 0; + JSArray* array = constructEmptyArray(exec, nullptr); + + DebuggerScope::iterator end = scopeChain->end(); + for (DebuggerScope::iterator iter = scopeChain->begin(); iter != end; ++iter) { + DebuggerScope* scope = iter.get(); + JSObject* description = constructEmptyObject(exec); + description->putDirect(exec->vm(), Identifier::fromString(exec, "type"), valueForScopeType(scope)); + description->putDirect(exec->vm(), Identifier::fromString(exec, "name"), jsString(exec, scope->name())); + description->putDirect(exec->vm(), Identifier::fromString(exec, "location"), valueForScopeLocation(exec, scope->location())); + array->putDirectIndex(exec, index++, description); + RETURN_IF_EXCEPTION(throwScope, JSValue()); } - ASSERT_NOT_REACHED(); - return jsUndefined(); + return array; } JSValue JSJavaScriptCallFrame::caller(ExecState* exec) const @@ -157,9 +182,9 @@ JSValue JSJavaScriptCallFrame::scopeChain(ExecState* exec) const if (!impl().scopeChain()) return jsNull(); - JSScope* scopeChain = impl().scopeChain(); - ScopeChainIterator iter = scopeChain->begin(); - ScopeChainIterator end = scopeChain->end(); + DebuggerScope* scopeChain = impl().scopeChain(); + DebuggerScope::iterator iter = scopeChain->begin(); + DebuggerScope::iterator end = scopeChain->end(); // We must always have something in the scope chain. ASSERT(iter != end); @@ -178,6 +203,11 @@ JSValue JSJavaScriptCallFrame::thisObject(ExecState*) const return impl().thisValue(); } +JSValue JSJavaScriptCallFrame::isTailDeleted(JSC::ExecState*) const +{ + return jsBoolean(impl().isTailDeleted()); +} + JSValue JSJavaScriptCallFrame::type(ExecState* exec) const { switch (impl().type()) { @@ -198,16 +228,10 @@ JSValue toJS(ExecState* exec, JSGlobalObject* globalObject, JavaScriptCallFrame* JSObject* prototype = JSJavaScriptCallFrame::createPrototype(exec->vm(), globalObject); Structure* structure = JSJavaScriptCallFrame::createStructure(exec->vm(), globalObject, prototype); - JSJavaScriptCallFrame* javaScriptCallFrame = JSJavaScriptCallFrame::create(exec->vm(), structure, impl); + JSJavaScriptCallFrame* javaScriptCallFrame = JSJavaScriptCallFrame::create(exec->vm(), structure, *impl); return javaScriptCallFrame; } -JSJavaScriptCallFrame* toJSJavaScriptCallFrame(JSValue value) -{ - return value.inherits(JSJavaScriptCallFrame::info()) ? jsCast<JSJavaScriptCallFrame*>(value) : nullptr; -} - } // namespace Inspector -#endif // ENABLE(INSPECTOR) |