summaryrefslogtreecommitdiff
path: root/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/bindings/js/JSDOMGlobalObject.cpp')
-rw-r--r--Source/WebCore/bindings/js/JSDOMGlobalObject.cpp183
1 files changed, 146 insertions, 37 deletions
diff --git a/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp b/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
index 27bd7894f..933650611 100644
--- a/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
+++ b/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -28,23 +28,42 @@
#include "JSDOMGlobalObject.h"
#include "Document.h"
+#include "JSDOMPromise.h"
#include "JSDOMWindow.h"
#include "JSEventListener.h"
+#include "JSMediaStream.h"
+#include "JSMediaStreamTrack.h"
+#include "JSRTCIceCandidate.h"
+#include "JSRTCSessionDescription.h"
+#include "JSReadableStream.h"
+#include "JSReadableStreamPrivateConstructors.h"
#include "JSWorkerGlobalScope.h"
+#include "RuntimeEnabledFeatures.h"
+#include "StructuredClone.h"
+#include "WebCoreJSClientData.h"
#include "WorkerGlobalScope.h"
+#include <builtins/BuiltinNames.h>
using namespace JSC;
namespace WebCore {
-const ClassInfo JSDOMGlobalObject::s_info = { "DOMGlobalObject", &JSGlobalObject::s_info, 0, 0, CREATE_METHOD_TABLE(JSDOMGlobalObject) };
+EncodedJSValue JSC_HOST_CALL makeThisTypeErrorForBuiltins(ExecState*);
+EncodedJSValue JSC_HOST_CALL makeGetterTypeErrorForBuiltins(ExecState*);
-JSDOMGlobalObject::JSDOMGlobalObject(VM& vm, Structure* structure, PassRefPtr<DOMWrapperWorld> world, const GlobalObjectMethodTable* globalObjectMethodTable)
+const ClassInfo JSDOMGlobalObject::s_info = { "DOMGlobalObject", &JSGlobalObject::s_info, 0, CREATE_METHOD_TABLE(JSDOMGlobalObject) };
+
+JSDOMGlobalObject::JSDOMGlobalObject(VM& vm, Structure* structure, Ref<DOMWrapperWorld>&& world, const GlobalObjectMethodTable* globalObjectMethodTable)
: JSGlobalObject(vm, structure, globalObjectMethodTable)
, m_currentEvent(0)
- , m_world(world)
+ , m_world(WTFMove(world))
+ , m_worldIsNormal(m_world->isNormal())
+ , m_builtinInternalFunctions(vm)
+{
+}
+
+JSDOMGlobalObject::~JSDOMGlobalObject()
{
- ASSERT(m_world);
}
void JSDOMGlobalObject::destroy(JSCell* cell)
@@ -52,33 +71,118 @@ void JSDOMGlobalObject::destroy(JSCell* cell)
static_cast<JSDOMGlobalObject*>(cell)->JSDOMGlobalObject::~JSDOMGlobalObject();
}
+EncodedJSValue JSC_HOST_CALL makeThisTypeErrorForBuiltins(ExecState* execState)
+{
+ ASSERT(execState);
+ ASSERT(execState->argumentCount() == 2);
+ VM& vm = execState->vm();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+
+ auto interfaceName = execState->uncheckedArgument(0).getString(execState);
+ ASSERT_UNUSED(scope, !scope.exception());
+ auto functionName = execState->uncheckedArgument(1).getString(execState);
+ ASSERT(!scope.exception());
+ return JSValue::encode(createTypeError(execState, makeThisTypeErrorMessage(interfaceName.utf8().data(), functionName.utf8().data())));
+}
+
+EncodedJSValue JSC_HOST_CALL makeGetterTypeErrorForBuiltins(ExecState* execState)
+{
+ ASSERT(execState);
+ ASSERT(execState->argumentCount() == 2);
+ VM& vm = execState->vm();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+
+ auto interfaceName = execState->uncheckedArgument(0).getString(execState);
+ ASSERT_UNUSED(scope, !scope.exception());
+ auto attributeName = execState->uncheckedArgument(1).getString(execState);
+ ASSERT(!scope.exception());
+ return JSValue::encode(createTypeError(execState, makeGetterTypeErrorMessage(interfaceName.utf8().data(), attributeName.utf8().data())));
+}
+
+void JSDOMGlobalObject::addBuiltinGlobals(VM& vm)
+{
+ m_builtinInternalFunctions.initialize(*this);
+
+#if ENABLE(READABLE_STREAM_API)
+ JSObject* privateReadableStreamDefaultControllerConstructor = createReadableStreamDefaultControllerPrivateConstructor(vm, *this);
+#if ENABLE(READABLE_BYTE_STREAM_API)
+ JSObject* privateReadableByteStreamControllerConstructor = createReadableByteStreamControllerPrivateConstructor(vm, *this);
+#endif
+ JSObject* privateReadableStreamDefaultReaderConstructor = createReadableStreamDefaultReaderPrivateConstructor(vm, *this);
+
+ ASSERT(!constructors(NoLockingNecessary).get(privateReadableStreamDefaultControllerConstructor->info()).get());
+#if ENABLE(READABLE_BYTE_STREAM_API)
+ ASSERT(!constructors(NoLockingNecessary).get(privateReadableByteStreamControllerConstructor->info()).get());
+#endif
+ ASSERT(!constructors(NoLockingNecessary).get(privateReadableStreamDefaultReaderConstructor->info()).get());
+ JSC::WriteBarrier<JSC::JSObject> temp;
+ {
+ auto locker = lockDuringMarking(vm.heap, m_gcLock);
+ constructors(locker).add(privateReadableStreamDefaultControllerConstructor->info(), temp).iterator->value.set(vm, this, privateReadableStreamDefaultControllerConstructor);
+#if ENABLE(READABLE_BYTE_STREAM_API)
+ constructors(locker).add(privateReadableByteStreamControllerConstructor->info(), temp).iterator->value.set(vm, this, privateReadableByteStreamControllerConstructor);
+#endif
+ constructors(locker).add(privateReadableStreamDefaultReaderConstructor->info(), temp).iterator->value.set(vm, this, privateReadableStreamDefaultReaderConstructor);
+ }
+#endif
+ JSVMClientData& clientData = *static_cast<JSVMClientData*>(vm.clientData);
+ JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().makeThisTypeErrorPrivateName(),
+ JSFunction::create(vm, this, 2, String(), makeThisTypeErrorForBuiltins), DontDelete | ReadOnly),
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().makeGetterTypeErrorPrivateName(),
+ JSFunction::create(vm, this, 2, String(), makeGetterTypeErrorForBuiltins), DontDelete | ReadOnly),
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().structuredCloneArrayBufferPrivateName(),
+ JSFunction::create(vm, this, 1, String(), structuredCloneArrayBuffer), DontDelete | ReadOnly),
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().structuredCloneArrayBufferViewPrivateName(),
+ JSFunction::create(vm, this, 1, String(), structuredCloneArrayBufferView), DontDelete | ReadOnly),
+ JSDOMGlobalObject::GlobalPropertyInfo(vm.propertyNames->builtinNames().ArrayBufferPrivateName(), getDirect(vm, vm.propertyNames->ArrayBuffer), DontDelete | ReadOnly),
+#if ENABLE(READABLE_STREAM_API) || ENABLE(WRITABLE_STREAM_API)
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamClosedPrivateName(), jsNumber(1), DontDelete | ReadOnly),
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamClosingPrivateName(), jsNumber(2), DontDelete | ReadOnly),
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamErroredPrivateName(), jsNumber(3), DontDelete | ReadOnly),
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamReadablePrivateName(), jsNumber(4), DontDelete | ReadOnly),
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamWaitingPrivateName(), jsNumber(5), DontDelete | ReadOnly),
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamWritablePrivateName(), jsNumber(6), DontDelete | ReadOnly),
+#endif
+#if ENABLE(READABLE_STREAM_API)
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().ReadableStreamDefaultControllerPrivateName(), privateReadableStreamDefaultControllerConstructor, DontDelete | ReadOnly),
+#if ENABLE(READABLE_BYTE_STREAM_API)
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().ReadableByteStreamControllerPrivateName(), privateReadableByteStreamControllerConstructor, DontDelete | ReadOnly),
+#endif
+ JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().ReadableStreamDefaultReaderPrivateName(), privateReadableStreamDefaultReaderConstructor, DontDelete | ReadOnly),
+#endif
+ };
+ addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
+}
+
void JSDOMGlobalObject::finishCreation(VM& vm)
{
Base::finishCreation(vm);
- ASSERT(inherits(info()));
+ ASSERT(inherits(vm, info()));
-#if ENABLE(REMOTE_INSPECTOR)
- setRemoteDebuggingEnabled(false);
-#endif
+ addBuiltinGlobals(vm);
+
+ RELEASE_ASSERT(classInfo());
}
void JSDOMGlobalObject::finishCreation(VM& vm, JSObject* thisValue)
{
Base::finishCreation(vm, thisValue);
- ASSERT(inherits(info()));
+ ASSERT(inherits(vm, info()));
-#if ENABLE(REMOTE_INSPECTOR)
- setRemoteDebuggingEnabled(false);
-#endif
+ addBuiltinGlobals(vm);
+
+ RELEASE_ASSERT(classInfo());
}
ScriptExecutionContext* JSDOMGlobalObject::scriptExecutionContext() const
{
- if (inherits(JSDOMWindowBase::info()))
+ if (inherits(vm(), JSDOMWindowBase::info()))
return jsCast<const JSDOMWindowBase*>(this)->scriptExecutionContext();
- if (inherits(JSWorkerGlobalScopeBase::info()))
+ if (inherits(vm(), JSWorkerGlobalScopeBase::info()))
return jsCast<const JSWorkerGlobalScopeBase*>(this)->scriptExecutionContext();
- ASSERT_NOT_REACHED();
+ dataLog("Unexpected global object: ", JSValue(this), "\n");
+ RELEASE_ASSERT_NOT_REACHED();
return 0;
}
@@ -86,17 +190,22 @@ void JSDOMGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
{
JSDOMGlobalObject* thisObject = jsCast<JSDOMGlobalObject*>(cell);
ASSERT_GC_OBJECT_INHERITS(thisObject, info());
- COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
- ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
Base::visitChildren(thisObject, visitor);
-
- JSDOMStructureMap::iterator end = thisObject->structures().end();
- for (JSDOMStructureMap::iterator it = thisObject->structures().begin(); it != end; ++it)
- visitor.append(&it->value);
-
- JSDOMConstructorMap::iterator end2 = thisObject->constructors().end();
- for (JSDOMConstructorMap::iterator it2 = thisObject->constructors().begin(); it2 != end2; ++it2)
- visitor.append(&it2->value);
+
+ {
+ auto locker = holdLock(thisObject->m_gcLock);
+
+ for (auto& structure : thisObject->structures(locker).values())
+ visitor.append(structure);
+
+ for (auto& constructor : thisObject->constructors(locker).values())
+ visitor.append(constructor);
+
+ for (auto& deferredPromise : thisObject->deferredPromises(locker))
+ deferredPromise->visitAggregate(visitor);
+ }
+
+ thisObject->m_builtinInternalFunctions.visit(visitor);
}
void JSDOMGlobalObject::setCurrentEvent(Event* currentEvent)
@@ -116,14 +225,14 @@ JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, JSC::ExecState* exec)
JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, JSC::ExecState* exec)
{
- if (scriptExecutionContext->isDocument())
- return toJSDOMGlobalObject(toDocument(scriptExecutionContext), exec);
+ if (is<Document>(*scriptExecutionContext))
+ return toJSDOMGlobalObject(downcast<Document>(scriptExecutionContext), exec);
- if (scriptExecutionContext->isWorkerGlobalScope())
- return static_cast<WorkerGlobalScope*>(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
+ if (is<WorkerGlobalScope>(*scriptExecutionContext))
+ return downcast<WorkerGlobalScope>(*scriptExecutionContext).script()->workerGlobalScopeWrapper();
ASSERT_NOT_REACHED();
- return 0;
+ return nullptr;
}
JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, DOMWrapperWorld& world)
@@ -133,14 +242,14 @@ JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, DOMWrapperWorld& worl
JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, DOMWrapperWorld& world)
{
- if (scriptExecutionContext->isDocument())
- return toJSDOMGlobalObject(toDocument(scriptExecutionContext), world);
+ if (is<Document>(*scriptExecutionContext))
+ return toJSDOMGlobalObject(downcast<Document>(scriptExecutionContext), world);
- if (scriptExecutionContext->isWorkerGlobalScope())
- return static_cast<WorkerGlobalScope*>(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
+ if (is<WorkerGlobalScope>(*scriptExecutionContext))
+ return downcast<WorkerGlobalScope>(*scriptExecutionContext).script()->workerGlobalScopeWrapper();
ASSERT_NOT_REACHED();
- return 0;
+ return nullptr;
}
} // namespace WebCore