summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp')
-rw-r--r--Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp359
1 files changed, 44 insertions, 315 deletions
diff --git a/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp b/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
index 3ad8bfa73..3f2f1ed4a 100644
--- a/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
+++ b/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2013 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,43 +26,30 @@
#include "config.h"
#include "JSInjectedScriptHost.h"
+#if ENABLE(INSPECTOR)
+
#include "DateInstance.h"
-#include "DirectArguments.h"
#include "Error.h"
#include "InjectedScriptHost.h"
-#include "IteratorOperations.h"
#include "JSArray.h"
-#include "JSArrayIterator.h"
-#include "JSBoundFunction.h"
-#include "JSCInlines.h"
#include "JSFunction.h"
#include "JSInjectedScriptHostPrototype.h"
-#include "JSMap.h"
-#include "JSMapIterator.h"
-#include "JSPromise.h"
-#include "JSPropertyNameIterator.h"
-#include "JSSet.h"
-#include "JSSetIterator.h"
-#include "JSStringIterator.h"
#include "JSTypedArrays.h"
-#include "JSWeakMap.h"
-#include "JSWeakSet.h"
#include "ObjectConstructor.h"
+#include "Operations.h"
#include "RegExpObject.h"
-#include "ScopedArguments.h"
#include "SourceCode.h"
#include "TypedArrayInlines.h"
-#include "WeakMapData.h"
using namespace JSC;
namespace Inspector {
-const ClassInfo JSInjectedScriptHost::s_info = { "InjectedScriptHost", &Base::s_info, 0, CREATE_METHOD_TABLE(JSInjectedScriptHost) };
+const ClassInfo JSInjectedScriptHost::s_info = { "InjectedScriptHost", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSInjectedScriptHost) };
-JSInjectedScriptHost::JSInjectedScriptHost(VM& vm, Structure* structure, Ref<InjectedScriptHost>&& impl)
+JSInjectedScriptHost::JSInjectedScriptHost(VM& vm, Structure* structure, PassRefPtr<InjectedScriptHost> impl)
: JSDestructibleObject(vm, structure)
- , m_wrapped(WTFMove(impl))
+ , m_impl(impl.leakRef())
{
}
@@ -83,6 +70,19 @@ void JSInjectedScriptHost::destroy(JSC::JSCell* cell)
thisObject->JSInjectedScriptHost::~JSInjectedScriptHost();
}
+void JSInjectedScriptHost::releaseImpl()
+{
+ if (m_impl) {
+ m_impl->deref();
+ m_impl = nullptr;
+ }
+}
+
+JSInjectedScriptHost::~JSInjectedScriptHost()
+{
+ releaseImpl();
+}
+
JSValue JSInjectedScriptHost::evaluate(ExecState* exec) const
{
JSGlobalObject* globalObject = exec->lexicalGlobalObject();
@@ -94,8 +94,9 @@ JSValue JSInjectedScriptHost::internalConstructorName(ExecState* exec)
if (exec->argumentCount() < 1)
return jsUndefined();
- JSObject* object = jsCast<JSObject*>(exec->uncheckedArgument(0).toThis(exec, NotStrictMode));
- return jsString(exec, JSObject::calculatedClassName(object));
+ JSObject* thisObject = jsCast<JSObject*>(exec->uncheckedArgument(0).toThis(exec, NotStrictMode));
+ String result = thisObject->methodTable()->className(thisObject);
+ return jsString(exec, result);
}
JSValue JSInjectedScriptHost::isHTMLAllCollection(ExecState* exec)
@@ -107,7 +108,7 @@ JSValue JSInjectedScriptHost::isHTMLAllCollection(ExecState* exec)
return jsBoolean(impl().isHTMLAllCollection(value));
}
-JSValue JSInjectedScriptHost::subtype(ExecState* exec)
+JSValue JSInjectedScriptHost::type(ExecState* exec)
{
if (exec->argumentCount() < 1)
return jsUndefined();
@@ -119,46 +120,13 @@ JSValue JSInjectedScriptHost::subtype(ExecState* exec)
return exec->vm().smallStrings.booleanString();
if (value.isNumber())
return exec->vm().smallStrings.numberString();
- if (value.isSymbol())
- return exec->vm().smallStrings.symbolString();
-
- JSObject* object = asObject(value);
- if (object) {
- if (object->isErrorInstance())
- return jsNontrivialString(exec, ASCIILiteral("error"));
-
- // Consider class constructor functions class objects.
- JSFunction* function = jsDynamicCast<JSFunction*>(value);
- if (function && function->isClassConstructorFunction())
- return jsNontrivialString(exec, ASCIILiteral("class"));
- }
if (value.inherits(JSArray::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
- if (value.inherits(DirectArguments::info()) || value.inherits(ScopedArguments::info()))
- return jsNontrivialString(exec, ASCIILiteral("array"));
-
if (value.inherits(DateInstance::info()))
return jsNontrivialString(exec, ASCIILiteral("date"));
if (value.inherits(RegExpObject::info()))
return jsNontrivialString(exec, ASCIILiteral("regexp"));
-
- if (value.inherits(JSMap::info()))
- return jsNontrivialString(exec, ASCIILiteral("map"));
- if (value.inherits(JSSet::info()))
- return jsNontrivialString(exec, ASCIILiteral("set"));
- if (value.inherits(JSWeakMap::info()))
- return jsNontrivialString(exec, ASCIILiteral("weakmap"));
- if (value.inherits(JSWeakSet::info()))
- return jsNontrivialString(exec, ASCIILiteral("weakset"));
-
- if (value.inherits(JSArrayIterator::info())
- || value.inherits(JSMapIterator::info())
- || value.inherits(JSSetIterator::info())
- || value.inherits(JSStringIterator::info())
- || value.inherits(JSPropertyNameIterator::info()))
- return jsNontrivialString(exec, ASCIILiteral("iterator"));
-
if (value.inherits(JSInt8Array::info()) || value.inherits(JSInt16Array::info()) || value.inherits(JSInt32Array::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
if (value.inherits(JSUint8Array::info()) || value.inherits(JSUint16Array::info()) || value.inherits(JSUint32Array::info()))
@@ -166,7 +134,7 @@ JSValue JSInjectedScriptHost::subtype(ExecState* exec)
if (value.inherits(JSFloat32Array::info()) || value.inherits(JSFloat64Array::info()))
return jsNontrivialString(exec, ASCIILiteral("array"));
- return impl().subtype(exec, value);
+ return impl().type(exec, value);
}
JSValue JSInjectedScriptHost::functionDetails(ExecState* exec)
@@ -178,37 +146,30 @@ JSValue JSInjectedScriptHost::functionDetails(ExecState* exec)
if (!value.asCell()->inherits(JSFunction::info()))
return jsUndefined();
- // FIXME: This should provide better details for JSBoundFunctions.
-
JSFunction* function = jsCast<JSFunction*>(value);
const SourceCode* sourceCode = function->sourceCode();
if (!sourceCode)
return jsUndefined();
- // In the inspector protocol all positions are 0-based while in SourceCode they are 1-based
int lineNumber = sourceCode->firstLine();
if (lineNumber)
- lineNumber -= 1;
- int columnNumber = sourceCode->startColumn();
- if (columnNumber)
- columnNumber -= 1;
+ lineNumber -= 1; // In the inspector protocol all positions are 0-based while in SourceCode they are 1-based
String scriptID = String::number(sourceCode->provider()->asID());
JSObject* location = constructEmptyObject(exec);
- location->putDirect(exec->vm(), Identifier::fromString(exec, "scriptId"), jsString(exec, scriptID));
- location->putDirect(exec->vm(), Identifier::fromString(exec, "lineNumber"), jsNumber(lineNumber));
- location->putDirect(exec->vm(), Identifier::fromString(exec, "columnNumber"), jsNumber(columnNumber));
+ location->putDirect(exec->vm(), Identifier(exec, "lineNumber"), jsNumber(lineNumber));
+ location->putDirect(exec->vm(), Identifier(exec, "scriptId"), jsString(exec, scriptID));
JSObject* result = constructEmptyObject(exec);
- result->putDirect(exec->vm(), Identifier::fromString(exec, "location"), location);
+ result->putDirect(exec->vm(), Identifier(exec, "location"), location);
String name = function->name(exec);
if (!name.isEmpty())
- result->putDirect(exec->vm(), Identifier::fromString(exec, "name"), jsString(exec, name));
+ result->putDirect(exec->vm(), Identifier(exec, "name"), jsString(exec, name));
String displayName = function->displayName(exec);
if (!displayName.isEmpty())
- result->putDirect(exec->vm(), Identifier::fromString(exec, "displayName"), jsString(exec, displayName));
+ result->putDirect(exec->vm(), Identifier(exec, "displayName"), jsString(exec, displayName));
// FIXME: provide function scope data in "scopesRaw" property when JSC supports it.
// <https://webkit.org/b/87192> [JSC] expose function (closure) inner context to debugger
@@ -216,261 +177,29 @@ JSValue JSInjectedScriptHost::functionDetails(ExecState* exec)
return result;
}
-static JSObject* constructInternalProperty(ExecState* exec, const String& name, JSValue value)
+JSValue JSInjectedScriptHost::getInternalProperties(ExecState*)
{
- JSObject* result = constructEmptyObject(exec);
- result->putDirect(exec->vm(), Identifier::fromString(exec, "name"), jsString(exec, name));
- result->putDirect(exec->vm(), Identifier::fromString(exec, "value"), value);
- return result;
-}
-
-JSValue JSInjectedScriptHost::getInternalProperties(ExecState* exec)
-{
- if (exec->argumentCount() < 1)
- return jsUndefined();
-
- JSValue value = exec->uncheckedArgument(0);
-
- if (JSPromise* promise = jsDynamicCast<JSPromise*>(value)) {
- unsigned index = 0;
- JSArray* array = constructEmptyArray(exec, nullptr);
- switch (promise->status(exec->vm())) {
- case JSPromise::Status::Pending:
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("status"), jsNontrivialString(exec, ASCIILiteral("pending"))));
- break;
- case JSPromise::Status::Fulfilled:
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("status"), jsNontrivialString(exec, ASCIILiteral("resolved"))));
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("result"), promise->result(exec->vm())));
- break;
- case JSPromise::Status::Rejected:
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("status"), jsNontrivialString(exec, ASCIILiteral("rejected"))));
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, ASCIILiteral("result"), promise->result(exec->vm())));
- break;
- }
- // FIXME: <https://webkit.org/b/141664> Web Inspector: ES6: Improved Support for Promises - Promise Reactions
- return array;
- }
-
- if (JSBoundFunction* boundFunction = jsDynamicCast<JSBoundFunction*>(value)) {
- unsigned index = 0;
- JSArray* array = constructEmptyArray(exec, nullptr, 3);
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "targetFunction", boundFunction->targetFunction()));
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "boundThis", boundFunction->boundThis()));
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "boundArgs", boundFunction->boundArgs()));
- return array;
- }
-
- if (JSArrayIterator* arrayIterator = jsDynamicCast<JSArrayIterator*>(value)) {
- String kind;
- switch (arrayIterator->kind(exec)) {
- case ArrayIterateKey:
- kind = ASCIILiteral("key");
- break;
- case ArrayIterateValue:
- kind = ASCIILiteral("value");
- break;
- case ArrayIterateKeyValue:
- kind = ASCIILiteral("key+value");
- break;
- }
- unsigned index = 0;
- JSArray* array = constructEmptyArray(exec, nullptr, 2);
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "array", arrayIterator->iteratedValue(exec)));
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", jsNontrivialString(exec, kind)));
- return array;
- }
-
- if (JSMapIterator* mapIterator = jsDynamicCast<JSMapIterator*>(value)) {
- String kind;
- switch (mapIterator->kind()) {
- case MapIterateKey:
- kind = ASCIILiteral("key");
- break;
- case MapIterateValue:
- kind = ASCIILiteral("value");
- break;
- case MapIterateKeyValue:
- kind = ASCIILiteral("key+value");
- break;
- }
- unsigned index = 0;
- JSArray* array = constructEmptyArray(exec, nullptr, 2);
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "map", mapIterator->iteratedValue()));
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", jsNontrivialString(exec, kind)));
- return array;
- }
-
- if (JSSetIterator* setIterator = jsDynamicCast<JSSetIterator*>(value)) {
- String kind;
- switch (setIterator->kind()) {
- case SetIterateKey:
- kind = ASCIILiteral("key");
- break;
- case SetIterateValue:
- kind = ASCIILiteral("value");
- break;
- case SetIterateKeyValue:
- kind = ASCIILiteral("key+value");
- break;
- }
- unsigned index = 0;
- JSArray* array = constructEmptyArray(exec, nullptr, 2);
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "set", setIterator->iteratedValue()));
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "kind", jsNontrivialString(exec, kind)));
- return array;
- }
-
- if (JSStringIterator* stringIterator = jsDynamicCast<JSStringIterator*>(value)) {
- unsigned index = 0;
- JSArray* array = constructEmptyArray(exec, nullptr, 1);
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "string", stringIterator->iteratedValue(exec)));
- return array;
- }
-
- if (JSPropertyNameIterator* propertyNameIterator = jsDynamicCast<JSPropertyNameIterator*>(value)) {
- unsigned index = 0;
- JSArray* array = constructEmptyArray(exec, nullptr, 1);
- array->putDirectIndex(exec, index++, constructInternalProperty(exec, "object", propertyNameIterator->iteratedValue()));
- return array;
- }
-
+ // FIXME: <https://webkit.org/b/94533> [JSC] expose object inner properties to debugger
return jsUndefined();
}
-JSValue JSInjectedScriptHost::weakMapSize(ExecState* exec)
-{
- if (exec->argumentCount() < 1)
- return jsUndefined();
-
- JSValue value = exec->uncheckedArgument(0);
- JSWeakMap* weakMap = jsDynamicCast<JSWeakMap*>(value);
- if (!weakMap)
- return jsUndefined();
-
- return jsNumber(weakMap->weakMapData()->size());
-}
-
-JSValue JSInjectedScriptHost::weakMapEntries(ExecState* exec)
+JSValue toJS(ExecState* exec, JSGlobalObject* globalObject, InjectedScriptHost* impl)
{
- if (exec->argumentCount() < 1)
- return jsUndefined();
+ if (!impl)
+ return jsNull();
- JSValue value = exec->uncheckedArgument(0);
- JSWeakMap* weakMap = jsDynamicCast<JSWeakMap*>(value);
- if (!weakMap)
- return jsUndefined();
-
- unsigned fetched = 0;
- unsigned numberToFetch = 100;
-
- JSValue numberToFetchArg = exec->argument(1);
- double fetchDouble = numberToFetchArg.toInteger(exec);
- if (fetchDouble >= 0)
- numberToFetch = static_cast<unsigned>(fetchDouble);
-
- JSArray* array = constructEmptyArray(exec, nullptr);
- for (auto it = weakMap->weakMapData()->begin(); it != weakMap->weakMapData()->end(); ++it) {
- JSObject* entry = constructEmptyObject(exec);
- entry->putDirect(exec->vm(), Identifier::fromString(exec, "key"), it->key);
- entry->putDirect(exec->vm(), Identifier::fromString(exec, "value"), it->value.get());
- array->putDirectIndex(exec, fetched++, entry);
- if (numberToFetch && fetched >= numberToFetch)
- break;
- }
+ JSObject* prototype = JSInjectedScriptHost::createPrototype(exec->vm(), globalObject);
+ Structure* structure = JSInjectedScriptHost::createStructure(exec->vm(), globalObject, prototype);
+ JSInjectedScriptHost* injectedScriptHost = JSInjectedScriptHost::create(exec->vm(), structure, impl);
- return array;
+ return injectedScriptHost;
}
-JSValue JSInjectedScriptHost::weakSetSize(ExecState* exec)
+JSInjectedScriptHost* toJSInjectedScriptHost(JSValue value)
{
- if (exec->argumentCount() < 1)
- return jsUndefined();
-
- JSValue value = exec->uncheckedArgument(0);
- JSWeakSet* weakSet = jsDynamicCast<JSWeakSet*>(value);
- if (!weakSet)
- return jsUndefined();
-
- return jsNumber(weakSet->weakMapData()->size());
-}
-
-JSValue JSInjectedScriptHost::weakSetEntries(ExecState* exec)
-{
- if (exec->argumentCount() < 1)
- return jsUndefined();
-
- JSValue value = exec->uncheckedArgument(0);
- JSWeakSet* weakSet = jsDynamicCast<JSWeakSet*>(value);
- if (!weakSet)
- return jsUndefined();
-
- unsigned fetched = 0;
- unsigned numberToFetch = 100;
-
- JSValue numberToFetchArg = exec->argument(1);
- double fetchDouble = numberToFetchArg.toInteger(exec);
- if (fetchDouble >= 0)
- numberToFetch = static_cast<unsigned>(fetchDouble);
-
- JSArray* array = constructEmptyArray(exec, nullptr);
- for (auto it = weakSet->weakMapData()->begin(); it != weakSet->weakMapData()->end(); ++it) {
- JSObject* entry = constructEmptyObject(exec);
- entry->putDirect(exec->vm(), Identifier::fromString(exec, "value"), it->key);
- array->putDirectIndex(exec, fetched++, entry);
- if (numberToFetch && fetched >= numberToFetch)
- break;
- }
-
- return array;
-}
-
-JSValue JSInjectedScriptHost::iteratorEntries(ExecState* exec)
-{
- if (exec->argumentCount() < 1)
- return jsUndefined();
-
- JSValue iterator;
- JSValue value = exec->uncheckedArgument(0);
- if (JSArrayIterator* arrayIterator = jsDynamicCast<JSArrayIterator*>(value))
- iterator = arrayIterator->clone(exec);
- else if (JSMapIterator* mapIterator = jsDynamicCast<JSMapIterator*>(value))
- iterator = mapIterator->clone(exec);
- else if (JSSetIterator* setIterator = jsDynamicCast<JSSetIterator*>(value))
- iterator = setIterator->clone(exec);
- else if (JSStringIterator* stringIterator = jsDynamicCast<JSStringIterator*>(value))
- iterator = stringIterator->clone(exec);
- else if (JSPropertyNameIterator* propertyNameIterator = jsDynamicCast<JSPropertyNameIterator*>(value))
- iterator = propertyNameIterator->clone(exec);
- else
- return jsUndefined();
-
- unsigned numberToFetch = 5;
- JSValue numberToFetchArg = exec->argument(1);
- double fetchDouble = numberToFetchArg.toInteger(exec);
- if (fetchDouble >= 0)
- numberToFetch = static_cast<unsigned>(fetchDouble);
-
- JSArray* array = constructEmptyArray(exec, nullptr);
-
- for (unsigned i = 0; i < numberToFetch; ++i) {
- JSValue next = iteratorStep(exec, iterator);
- if (exec->hadException())
- break;
- if (next.isFalse())
- break;
-
- JSValue nextValue = iteratorValue(exec, next);
- if (exec->hadException())
- break;
-
- JSObject* entry = constructEmptyObject(exec);
- entry->putDirect(exec->vm(), Identifier::fromString(exec, "value"), nextValue);
- array->putDirectIndex(exec, i, entry);
- }
-
- iteratorClose(exec, iterator);
-
- return array;
+ return value.inherits(JSInjectedScriptHost::info()) ? jsCast<JSInjectedScriptHost*>(value) : nullptr;
}
} // namespace Inspector
+
+#endif // ENABLE(INSPECTOR)