toThis() on a JSWorkerGlobalScope should return a JSProxy and not undefined
https://bugs.webkit.org/show_bug.cgi?id=130554
Reviewed by Geoffrey Garen.
Source/JavaScriptCore:
Fixed toThis() on WorkerGlobalScope to return a JSProxy instead of the JSGlobalObject.
Did some cleanup as well. Moved the setting of the thisObject in a JSGlobalObject to
happen in finishCreation() so that it will also happen for other derived classes including
JSWorkerGlobalScopeBase.
* API/JSContextRef.cpp:
(JSGlobalContextCreateInGroup):
* jsc.cpp:
(GlobalObject::create):
* API/tests/testapi.c:
(globalObject_initialize): Eliminated ASSERT that the global object we are creating matches
the result from JSContextGetGlobalObject() as that will return the proxy.
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init): Removed thisValue parameter and the call to setGlobalThis() since
we now call setGlobalThis in finishCreation().
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::finishCreation):
(JSC::JSGlobalObject::setGlobalThis): Made this a private method.
Source/WebCore:
Fixed toThis() on WorkerGlobalScope to return a JSProxy instead of the JSGlobalObject.
Added cast from JSProxy->target() if the jsCast<>() to the native object fails
in toJSDedicatedWorkerGlobalScope() and toJSSharedWorkerGlobalScope().
The original cast is needed for access to the local side of the worker, while the JSProxy
cast is used on the remote side of a worker.
Test: fast/workers/worker-strict.html
* bindings/js/JSWorkerGlobalScopeBase.cpp:
(WebCore::toJSDedicatedWorkerGlobalScope):
(WebCore::toJSSharedWorkerGlobalScope):
* bindings/js/WorkerScriptController.cpp:
(WebCore::WorkerScriptController::evaluate): Changed to pass in the JSProxy and not
the WorkerGlobalScope object as the this object to script evaluation.
* workers/DedicatedWorkerGlobalScope.idl:
* workers/SharedWorkerGlobalScope.idl:
* workers/WorkerGlobalScope.idl:
Added the new CustomProxyToJSObject attribute so we'll call to<{nativeClass}>() for
getting the object to use for global evaluation.
LayoutTests:
Fixed toThis() on WorkerGlobalScope to return a JSProxy instead of the JSGlobalObject.
New regressions tests.
* fast/workers/resources/worker-strict.js: Added.
* fast/workers/worker-strict-expected.txt: Added.
* fast/workers/worker-strict.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@166126 268f45cc-cd09-0410-ab3c-d52691b4dbfc
16 files changed