Title: [221546] trunk/Source/_javascript_Core
Revision
221546
Author
[email protected]
Date
2017-09-02 21:42:51 -0700 (Sat, 02 Sep 2017)

Log Message

Need an API to get the global context from JSObjectRef
https://bugs.webkit.org/show_bug.cgi?id=176291

Reviewed by Saam Barati.

Very simple additional API, starting off as SPI on principle.

* API/JSObjectRef.cpp:
(JSObjectGetGlobalContext):
* API/JSObjectRefPrivate.h:
* API/tests/testapi.c:
(main):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSObjectRef.cpp (221545 => 221546)


--- trunk/Source/_javascript_Core/API/JSObjectRef.cpp	2017-09-03 04:05:00 UTC (rev 221545)
+++ trunk/Source/_javascript_Core/API/JSObjectRef.cpp	2017-09-03 04:42:51 UTC (rev 221546)
@@ -691,3 +691,12 @@
         result = proxy->target();
     return toRef(result);
 }
+
+JSGlobalContextRef JSObjectGetGlobalContext(JSObjectRef objectRef)
+{
+    JSObject* object = toJS(objectRef);
+    if (!object)
+        return nullptr;
+    return reinterpret_cast<JSGlobalContextRef>(object->globalObject()->globalExec());
+}
+

Modified: trunk/Source/_javascript_Core/API/JSObjectRefPrivate.h (221545 => 221546)


--- trunk/Source/_javascript_Core/API/JSObjectRefPrivate.h	2017-09-03 04:05:00 UTC (rev 221545)
+++ trunk/Source/_javascript_Core/API/JSObjectRefPrivate.h	2017-09-03 04:42:51 UTC (rev 221546)
@@ -69,6 +69,8 @@
 
 JS_EXPORT JSObjectRef JSObjectGetProxyTarget(JSObjectRef);
 
+JS_EXPORT JSGlobalContextRef JSObjectGetGlobalContext(JSObjectRef object);
+    
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/Source/_javascript_Core/API/tests/testapi.c (221545 => 221546)


--- trunk/Source/_javascript_Core/API/tests/testapi.c	2017-09-03 04:05:00 UTC (rev 221545)
+++ trunk/Source/_javascript_Core/API/tests/testapi.c	2017-09-03 04:42:51 UTC (rev 221546)
@@ -2040,6 +2040,22 @@
         JSGlobalContextRelease(context);
     }
 
+    // Check JSObjectGetGlobalContext
+    {
+        JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL);
+        {
+            JSObjectRef globalObject = JSContextGetGlobalObject(context);
+            assertTrue(JSObjectGetGlobalContext(globalObject) == context, "global object context is correct");
+            JSObjectRef object = JSObjectMake(context, NULL, NULL);
+            assertTrue(JSObjectGetGlobalContext(object) == context, "regular object context is correct");
+            JSStringRef returnFunctionSource = JSStringCreateWithUTF8CString("return this;");
+            JSObjectRef theFunction = JSObjectMakeFunction(context, NULL, 0, NULL, returnFunctionSource, NULL, 1, NULL);
+            assertTrue(JSObjectGetGlobalContext(theFunction) == context, "function object context is correct");
+            assertTrue(JSObjectGetGlobalContext(NULL) == NULL, "NULL object context is NULL");
+            JSStringRelease(returnFunctionSource);
+        }
+        JSGlobalContextRelease(context);
+    }
     failed = testTypedArrayCAPI() || failed;
     failed = testExecutionTimeLimit() || failed;
     failed = testFunctionOverrides() || failed;

Modified: trunk/Source/_javascript_Core/ChangeLog (221545 => 221546)


--- trunk/Source/_javascript_Core/ChangeLog	2017-09-03 04:05:00 UTC (rev 221545)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-09-03 04:42:51 UTC (rev 221546)
@@ -1,3 +1,18 @@
+2017-09-02  Oliver Hunt  <[email protected]>
+
+        Need an API to get the global context from JSObjectRef
+        https://bugs.webkit.org/show_bug.cgi?id=176291
+
+        Reviewed by Saam Barati.
+
+        Very simple additional API, starting off as SPI on principle.
+
+        * API/JSObjectRef.cpp:
+        (JSObjectGetGlobalContext):
+        * API/JSObjectRefPrivate.h:
+        * API/tests/testapi.c:
+        (main):
+
 2017-09-02  Yusuke Suzuki  <[email protected]>
 
         [DFG] Relax arity requirement
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to