Title: [223274] trunk
Revision
223274
Author
[email protected]
Date
2017-10-12 19:13:20 -0700 (Thu, 12 Oct 2017)

Log Message

WebAssembly: Wasm functions should have either JSFunctionType or TypeOfShouldCallGetCallData
https://bugs.webkit.org/show_bug.cgi?id=178210

Reviewed by Saam Barati.

JSTests:

* wasm/function-tests/trap-from-start-async.js:
(async.StartTrapsAsync):
* wasm/function-tests/trap-from-start.js:
(StartTraps):
* wasm/js-api/web-assembly-function.js:
(assert.eq.Object.getPrototypeOf):
* wasm/js-api/wrapper-function.js:
(return.new.WebAssembly.Module):
(assert.throws.makeInstance): Deleted.
(assert.throws.Bar): Deleted.
(assert.throws): Deleted.

Source/_javascript_Core:

In Wasm, we have two JS functions exposed to users: WebAssemblyFunction and WebAssemblyWrapperFunction.
The former is an exported wasm function and the latter is an imported & exported function. Since they
have [[Call]], they should be categorized into "function" in typeof operation.

However, these functions do not implement our function protocol correctly. They inherit JSFunction.
But JSType of WebAssemblyFunction is WebAssemblyFunctionType, and one of WebAssemblyWrapperFunction is
ObjectType. Since both do not have TypeOfShouldCallGetCallData, they return "object" when performing
typeof operation.

In this patch, we address the above issue by the following 2 fixes.

1. We add TypeOfShouldCallGetCallData to WebAssemblyFunction. This is the same way how we implement
InternalFunction. Since WebAssemblyFunction requires WebAssemblyFunctionType for fast checking in Wasm
implementation, we cannot make this JSFunctionType.

2. On the other hand, WebAssemblyWrapperFunction does not require a specific JSType. So this patch
changes JSType of WebAssemblyWrapperFunction to JSFunctionType. JSFunctionType can be usable for derived
classes of JSFunction (e.g. JSCustomGetterSetterFunction).

* wasm/js/WebAssemblyFunction.h:
(JSC::WebAssemblyFunction::signatureIndex const): Deleted.
(JSC::WebAssemblyFunction::wasmEntrypointLoadLocation const): Deleted.
(JSC::WebAssemblyFunction::callableFunction const): Deleted.
(JSC::WebAssemblyFunction::jsEntrypoint): Deleted.
(JSC::WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation): Deleted.
* wasm/js/WebAssemblyWrapperFunction.cpp:
(JSC::WebAssemblyWrapperFunction::createStructure):
* wasm/js/WebAssemblyWrapperFunction.h:
(JSC::WebAssemblyWrapperFunction::signatureIndex const): Deleted.
(JSC::WebAssemblyWrapperFunction::wasmEntrypointLoadLocation const): Deleted.
(JSC::WebAssemblyWrapperFunction::callableFunction const): Deleted.
(JSC::WebAssemblyWrapperFunction::function): Deleted.

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (223273 => 223274)


--- trunk/JSTests/ChangeLog	2017-10-13 02:04:33 UTC (rev 223273)
+++ trunk/JSTests/ChangeLog	2017-10-13 02:13:20 UTC (rev 223274)
@@ -1,3 +1,22 @@
+2017-10-12  Yusuke Suzuki  <[email protected]>
+
+        WebAssembly: Wasm functions should have either JSFunctionType or TypeOfShouldCallGetCallData
+        https://bugs.webkit.org/show_bug.cgi?id=178210
+
+        Reviewed by Saam Barati.
+
+        * wasm/function-tests/trap-from-start-async.js:
+        (async.StartTrapsAsync):
+        * wasm/function-tests/trap-from-start.js:
+        (StartTraps):
+        * wasm/js-api/web-assembly-function.js:
+        (assert.eq.Object.getPrototypeOf):
+        * wasm/js-api/wrapper-function.js:
+        (return.new.WebAssembly.Module):
+        (assert.throws.makeInstance): Deleted.
+        (assert.throws.Bar): Deleted.
+        (assert.throws): Deleted.
+
 2017-09-29  Filip Pizlo  <[email protected]>
 
         Enable gigacage on iOS

Modified: trunk/JSTests/wasm/function-tests/trap-from-start-async.js (223273 => 223274)


--- trunk/JSTests/wasm/function-tests/trap-from-start-async.js	2017-10-13 02:04:33 UTC (rev 223273)
+++ trunk/JSTests/wasm/function-tests/trap-from-start-async.js	2017-10-13 02:13:20 UTC (rev 223274)
@@ -62,8 +62,8 @@
 
     for (let i = 0; i < table.length; ++i) {
         switch (i) {
-        case 4:  assert.isObject(table.get(i)); break;
-        case 5:  assert.isObject(table.get(i)); break;
+        case 4:  assert.isFunction(table.get(i)); break;
+        case 5:  assert.isFunction(table.get(i)); break;
         default: assert.eq(table.get(i), null); break;
         }
     }

Modified: trunk/JSTests/wasm/function-tests/trap-from-start.js (223273 => 223274)


--- trunk/JSTests/wasm/function-tests/trap-from-start.js	2017-10-13 02:04:33 UTC (rev 223273)
+++ trunk/JSTests/wasm/function-tests/trap-from-start.js	2017-10-13 02:13:20 UTC (rev 223274)
@@ -61,8 +61,8 @@
 
     for (let i = 0; i < table.length; ++i) {
         switch (i) {
-        case 4:  assert.isObject(table.get(i)); break;
-        case 5:  assert.isObject(table.get(i)); break;
+        case 4:  assert.isFunction(table.get(i)); break;
+        case 5:  assert.isFunction(table.get(i)); break;
         default: assert.eq(table.get(i), null); break;
         }
     }

Modified: trunk/JSTests/wasm/js-api/web-assembly-function.js (223273 => 223274)


--- trunk/JSTests/wasm/js-api/web-assembly-function.js	2017-10-13 02:04:33 UTC (rev 223273)
+++ trunk/JSTests/wasm/js-api/web-assembly-function.js	2017-10-13 02:13:20 UTC (rev 223274)
@@ -18,3 +18,8 @@
 const instance = new WebAssembly.Instance(module);
 
 assert.eq(Object.getPrototypeOf(instance.exports.foo), Function.prototype);
+{
+    assert.truthy(typeof instance.exports.foo === "function", "is_function bytecode should handle wasm function.");
+    let value = typeof instance.exports.foo;
+    assert.eq(value, "function", "the result of typeof should be 'function'");
+}

Modified: trunk/JSTests/wasm/js-api/wrapper-function.js (223273 => 223274)


--- trunk/JSTests/wasm/js-api/wrapper-function.js	2017-10-13 02:04:33 UTC (rev 223273)
+++ trunk/JSTests/wasm/js-api/wrapper-function.js	2017-10-13 02:13:20 UTC (rev 223274)
@@ -48,6 +48,11 @@
         assert.throws(() => new WebAssembly.Instance(module, {imp: {f: instance.exports.func}}), WebAssembly.LinkError, "imported function imp:f signature doesn't match the provided WebAssembly function's signature");
     }
 
+    {
+        assert.truthy(typeof instance.exports.func === "function", "is_function bytecode should handle wrapper function.");
+        let value = typeof instance.exports.func;
+        assert.eq(value, "function", "the result of typeof should be 'function'");
+    }
 }
 
 {

Modified: trunk/Source/_javascript_Core/ChangeLog (223273 => 223274)


--- trunk/Source/_javascript_Core/ChangeLog	2017-10-13 02:04:33 UTC (rev 223273)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-10-13 02:13:20 UTC (rev 223274)
@@ -1,3 +1,43 @@
+2017-10-12  Yusuke Suzuki  <[email protected]>
+
+        WebAssembly: Wasm functions should have either JSFunctionType or TypeOfShouldCallGetCallData
+        https://bugs.webkit.org/show_bug.cgi?id=178210
+
+        Reviewed by Saam Barati.
+
+        In Wasm, we have two JS functions exposed to users: WebAssemblyFunction and WebAssemblyWrapperFunction.
+        The former is an exported wasm function and the latter is an imported & exported function. Since they
+        have [[Call]], they should be categorized into "function" in typeof operation.
+
+        However, these functions do not implement our function protocol correctly. They inherit JSFunction.
+        But JSType of WebAssemblyFunction is WebAssemblyFunctionType, and one of WebAssemblyWrapperFunction is
+        ObjectType. Since both do not have TypeOfShouldCallGetCallData, they return "object" when performing
+        typeof operation.
+
+        In this patch, we address the above issue by the following 2 fixes.
+
+        1. We add TypeOfShouldCallGetCallData to WebAssemblyFunction. This is the same way how we implement
+        InternalFunction. Since WebAssemblyFunction requires WebAssemblyFunctionType for fast checking in Wasm
+        implementation, we cannot make this JSFunctionType.
+
+        2. On the other hand, WebAssemblyWrapperFunction does not require a specific JSType. So this patch
+        changes JSType of WebAssemblyWrapperFunction to JSFunctionType. JSFunctionType can be usable for derived
+        classes of JSFunction (e.g. JSCustomGetterSetterFunction).
+
+        * wasm/js/WebAssemblyFunction.h:
+        (JSC::WebAssemblyFunction::signatureIndex const): Deleted.
+        (JSC::WebAssemblyFunction::wasmEntrypointLoadLocation const): Deleted.
+        (JSC::WebAssemblyFunction::callableFunction const): Deleted.
+        (JSC::WebAssemblyFunction::jsEntrypoint): Deleted.
+        (JSC::WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation): Deleted.
+        * wasm/js/WebAssemblyWrapperFunction.cpp:
+        (JSC::WebAssemblyWrapperFunction::createStructure):
+        * wasm/js/WebAssemblyWrapperFunction.h:
+        (JSC::WebAssemblyWrapperFunction::signatureIndex const): Deleted.
+        (JSC::WebAssemblyWrapperFunction::wasmEntrypointLoadLocation const): Deleted.
+        (JSC::WebAssemblyWrapperFunction::callableFunction const): Deleted.
+        (JSC::WebAssemblyWrapperFunction::function): Deleted.
+
 2017-10-12  Per Arne Vollan  <[email protected]>
 
         [Win64] JSC compile error.

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyFunction.h (223273 => 223274)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyFunction.h	2017-10-13 02:04:33 UTC (rev 223273)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyFunction.h	2017-10-13 02:13:20 UTC (rev 223274)
@@ -41,11 +41,11 @@
 class Compilation;
 }
 
-class WebAssemblyFunction : public WebAssemblyFunctionBase {
+class WebAssemblyFunction final : public WebAssemblyFunctionBase {
 public:
     using Base = WebAssemblyFunctionBase;
 
-    const static unsigned StructureFlags = Base::StructureFlags;
+    const static unsigned StructureFlags = Base::StructureFlags | TypeOfShouldCallGetCallData;
 
     DECLARE_EXPORT_INFO;
 

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyWrapperFunction.cpp (223273 => 223274)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyWrapperFunction.cpp	2017-10-13 02:04:33 UTC (rev 223273)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyWrapperFunction.cpp	2017-10-13 02:13:20 UTC (rev 223274)
@@ -79,7 +79,7 @@
 Structure* WebAssemblyWrapperFunction::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
 {
     ASSERT(globalObject);
-    return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+    return Structure::create(vm, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), info());
 }
 
 void WebAssemblyWrapperFunction::visitChildren(JSCell* cell, SlotVisitor& visitor)

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyWrapperFunction.h (223273 => 223274)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyWrapperFunction.h	2017-10-13 02:04:33 UTC (rev 223273)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyWrapperFunction.h	2017-10-13 02:13:20 UTC (rev 223274)
@@ -32,7 +32,7 @@
 
 namespace JSC {
 
-class WebAssemblyWrapperFunction : public WebAssemblyFunctionBase {
+class WebAssemblyWrapperFunction final : public WebAssemblyFunctionBase {
 public:
     using Base = WebAssemblyFunctionBase;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to