Expose $vm if window.internals is exposed
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 May 2018 03:01:43 +0000 (03:01 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 May 2018 03:01:43 +0000 (03:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185900

Reviewed by Mark Lam.

This is useful for testing vm internals when running LayoutTests.

Source/JavaScriptCore:

* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):
(JSC::JSGlobalObject::exposeDollarVM):
* runtime/JSGlobalObject.h:

Source/WebCore:

* testing/js/WebCoreTestSupport.cpp:
(WebCoreTestSupport::injectInternalsObject):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232143 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/WebCore/ChangeLog
Source/WebCore/testing/js/WebCoreTestSupport.cpp

index 28a319a..3e27107 100644 (file)
@@ -1,5 +1,20 @@
 2018-05-23  Keith Miller  <keith_miller@apple.com>
 
+        Expose $vm if window.internals is exposed
+        https://bugs.webkit.org/show_bug.cgi?id=185900
+
+        Reviewed by Mark Lam.
+
+        This is useful for testing vm internals when running LayoutTests.
+
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        (JSC::JSGlobalObject::visitChildren):
+        (JSC::JSGlobalObject::exposeDollarVM):
+        * runtime/JSGlobalObject.h:
+
+2018-05-23  Keith Miller  <keith_miller@apple.com>
+
         Define length on CoW array should properly convert to writable
         https://bugs.webkit.org/show_bug.cgi?id=185927
 
index 75a252c..e7065e3 100644 (file)
@@ -964,17 +964,8 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
 
     m_linkTimeConstants[static_cast<unsigned>(LinkTimeConstant::ThrowTypeErrorFunction)] = m_throwTypeErrorFunction.get();
 
-    if (UNLIKELY(Options::useDollarVM())) {
-        m_dollarVMStructure.set(vm, this, JSDollarVM::createStructure(vm, this, m_objectPrototype.get()));
-        JSDollarVM* dollarVM = JSDollarVM::create(vm, m_dollarVMStructure.get());
-
-        GlobalPropertyInfo extraStaticGlobals[] = {
-            GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
-        };
-        addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
-
-        putDirectWithoutTransition(vm, Identifier::fromString(exec, "$vm"), dollarVM, static_cast<unsigned>(PropertyAttribute::DontEnum));
-    }
+    if (UNLIKELY(Options::useDollarVM()))
+        exposeDollarVM();
 
 #if ENABLE(WEBASSEMBLY)
     if (Options::useWebAssembly()) {
@@ -1429,7 +1420,6 @@ void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
     visitor.append(thisObject->m_regExpMatchesArrayWithGroupsStructure);
     visitor.append(thisObject->m_moduleRecordStructure);
     visitor.append(thisObject->m_moduleNamespaceObjectStructure);
-    visitor.append(thisObject->m_dollarVMStructure);
     visitor.append(thisObject->m_proxyObjectStructure);
     visitor.append(thisObject->m_callableProxyObjectStructure);
     visitor.append(thisObject->m_proxyRevokeStructure);
@@ -1482,6 +1472,23 @@ ExecState* JSGlobalObject::globalExec()
     return CallFrame::create(m_globalCallFrame);
 }
 
+void JSGlobalObject::exposeDollarVM()
+{
+    VM& vm = this->vm();
+
+    if (hasOwnProperty(globalExec(), vm.propertyNames->builtinNames().dollarVMPrivateName()))
+        return;
+
+    JSDollarVM* dollarVM = JSDollarVM::create(vm, JSDollarVM::createStructure(vm, this, m_objectPrototype.get()));
+
+    GlobalPropertyInfo extraStaticGlobals[] = {
+        GlobalPropertyInfo(vm.propertyNames->builtinNames().dollarVMPrivateName(), dollarVM, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
+    };
+    addStaticGlobals(extraStaticGlobals, WTF_ARRAY_LENGTH(extraStaticGlobals));
+
+    putDirect(vm, Identifier::fromString(globalExec(), "$vm"), dollarVM, static_cast<unsigned>(PropertyAttribute::DontEnum));
+}
+
 void JSGlobalObject::addStaticGlobals(GlobalPropertyInfo* globals, int count)
 {
     ScopeOffset startOffset = addVariables(count, jsUndefined());
index 69b6c8f..52d211c 100644 (file)
@@ -355,7 +355,6 @@ public:
     WriteBarrier<Structure> m_asyncFunctionStructure;
     WriteBarrier<Structure> m_asyncGeneratorFunctionStructure;
     WriteBarrier<Structure> m_generatorFunctionStructure;
-    WriteBarrier<Structure> m_dollarVMStructure;
     WriteBarrier<Structure> m_iteratorResultObjectStructure;
     WriteBarrier<Structure> m_regExpMatchesArrayStructure;
     WriteBarrier<Structure> m_regExpMatchesArrayWithGroupsStructure;
@@ -902,6 +901,7 @@ public:
     WeakRandom& weakRandom() { return m_weakRandom; }
 
     bool needsSiteSpecificQuirks() const { return m_needsSiteSpecificQuirks; }
+    JS_EXPORT_PRIVATE void exposeDollarVM();
 
 #if JSC_OBJC_API_ENABLED
     JSWrapperMap* wrapperMap() const { return m_wrapperMap.get(); }
index c719b83..f617f32 100644 (file)
@@ -1,3 +1,15 @@
+2018-05-23  Keith Miller  <keith_miller@apple.com>
+
+        Expose $vm if window.internals is exposed
+        https://bugs.webkit.org/show_bug.cgi?id=185900
+
+        Reviewed by Mark Lam.
+
+        This is useful for testing vm internals when running LayoutTests.
+
+        * testing/js/WebCoreTestSupport.cpp:
+        (WebCoreTestSupport::injectInternalsObject):
+
 2018-05-23  David Kilzer  <ddkilzer@apple.com>
 
         Don't create the SubimageCache just to clear an image from it
index c018cee..9f6ff2a 100644 (file)
@@ -57,8 +57,10 @@ void injectInternalsObject(JSContextRef context)
     JSLockHolder lock(exec);
     JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
     ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
-    if (is<Document>(*scriptContext))
+    if (is<Document>(*scriptContext)) {
         globalObject->putDirect(exec->vm(), Identifier::fromString(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(downcast<Document>(*scriptContext))));
+        globalObject->exposeDollarVM();
+    }
 }
 
 void resetInternalsObject(JSContextRef context)