Changeset 223274 in webkit


Ignore:
Timestamp:
Oct 12, 2017 7:13:20 PM (6 years ago)
Author:
Yusuke Suzuki
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/JavaScriptCore:

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.

  1. 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.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r223239 r223274  
     12017-10-12  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        WebAssembly: Wasm functions should have either JSFunctionType or TypeOfShouldCallGetCallData
     4        https://bugs.webkit.org/show_bug.cgi?id=178210
     5
     6        Reviewed by Saam Barati.
     7
     8        * wasm/function-tests/trap-from-start-async.js:
     9        (async.StartTrapsAsync):
     10        * wasm/function-tests/trap-from-start.js:
     11        (StartTraps):
     12        * wasm/js-api/web-assembly-function.js:
     13        (assert.eq.Object.getPrototypeOf):
     14        * wasm/js-api/wrapper-function.js:
     15        (return.new.WebAssembly.Module):
     16        (assert.throws.makeInstance): Deleted.
     17        (assert.throws.Bar): Deleted.
     18        (assert.throws): Deleted.
     19
    1202017-09-29  Filip Pizlo  <fpizlo@apple.com>
    221
  • trunk/JSTests/wasm/function-tests/trap-from-start-async.js

    r219969 r223274  
    6363    for (let i = 0; i < table.length; ++i) {
    6464        switch (i) {
    65         case 4:  assert.isObject(table.get(i)); break;
    66         case 5:  assert.isObject(table.get(i)); break;
     65        case 4:  assert.isFunction(table.get(i)); break;
     66        case 5:  assert.isFunction(table.get(i)); break;
    6767        default: assert.eq(table.get(i), null); break;
    6868        }
  • trunk/JSTests/wasm/function-tests/trap-from-start.js

    r219969 r223274  
    6262    for (let i = 0; i < table.length; ++i) {
    6363        switch (i) {
    64         case 4:  assert.isObject(table.get(i)); break;
    65         case 5:  assert.isObject(table.get(i)); break;
     64        case 4:  assert.isFunction(table.get(i)); break;
     65        case 5:  assert.isFunction(table.get(i)); break;
    6666        default: assert.eq(table.get(i), null); break;
    6767        }
  • trunk/JSTests/wasm/js-api/web-assembly-function.js

    r213313 r223274  
    1919
    2020assert.eq(Object.getPrototypeOf(instance.exports.foo), Function.prototype);
     21{
     22    assert.truthy(typeof instance.exports.foo === "function", "is_function bytecode should handle wasm function.");
     23    let value = typeof instance.exports.foo;
     24    assert.eq(value, "function", "the result of typeof should be 'function'");
     25}
  • trunk/JSTests/wasm/js-api/wrapper-function.js

    r217921 r223274  
    4949    }
    5050
     51    {
     52        assert.truthy(typeof instance.exports.func === "function", "is_function bytecode should handle wrapper function.");
     53        let value = typeof instance.exports.func;
     54        assert.eq(value, "function", "the result of typeof should be 'function'");
     55    }
    5156}
    5257
  • trunk/Source/JavaScriptCore/ChangeLog

    r223248 r223274  
     12017-10-12  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        WebAssembly: Wasm functions should have either JSFunctionType or TypeOfShouldCallGetCallData
     4        https://bugs.webkit.org/show_bug.cgi?id=178210
     5
     6        Reviewed by Saam Barati.
     7
     8        In Wasm, we have two JS functions exposed to users: WebAssemblyFunction and WebAssemblyWrapperFunction.
     9        The former is an exported wasm function and the latter is an imported & exported function. Since they
     10        have [[Call]], they should be categorized into "function" in typeof operation.
     11
     12        However, these functions do not implement our function protocol correctly. They inherit JSFunction.
     13        But JSType of WebAssemblyFunction is WebAssemblyFunctionType, and one of WebAssemblyWrapperFunction is
     14        ObjectType. Since both do not have TypeOfShouldCallGetCallData, they return "object" when performing
     15        typeof operation.
     16
     17        In this patch, we address the above issue by the following 2 fixes.
     18
     19        1. We add TypeOfShouldCallGetCallData to WebAssemblyFunction. This is the same way how we implement
     20        InternalFunction. Since WebAssemblyFunction requires WebAssemblyFunctionType for fast checking in Wasm
     21        implementation, we cannot make this JSFunctionType.
     22
     23        2. On the other hand, WebAssemblyWrapperFunction does not require a specific JSType. So this patch
     24        changes JSType of WebAssemblyWrapperFunction to JSFunctionType. JSFunctionType can be usable for derived
     25        classes of JSFunction (e.g. JSCustomGetterSetterFunction).
     26
     27        * wasm/js/WebAssemblyFunction.h:
     28        (JSC::WebAssemblyFunction::signatureIndex const): Deleted.
     29        (JSC::WebAssemblyFunction::wasmEntrypointLoadLocation const): Deleted.
     30        (JSC::WebAssemblyFunction::callableFunction const): Deleted.
     31        (JSC::WebAssemblyFunction::jsEntrypoint): Deleted.
     32        (JSC::WebAssemblyFunction::offsetOfWasmEntrypointLoadLocation): Deleted.
     33        * wasm/js/WebAssemblyWrapperFunction.cpp:
     34        (JSC::WebAssemblyWrapperFunction::createStructure):
     35        * wasm/js/WebAssemblyWrapperFunction.h:
     36        (JSC::WebAssemblyWrapperFunction::signatureIndex const): Deleted.
     37        (JSC::WebAssemblyWrapperFunction::wasmEntrypointLoadLocation const): Deleted.
     38        (JSC::WebAssemblyWrapperFunction::callableFunction const): Deleted.
     39        (JSC::WebAssemblyWrapperFunction::function): Deleted.
     40
    1412017-10-12  Per Arne Vollan  <pvollan@apple.com>
    242
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.h

    r217645 r223274  
    4242}
    4343
    44 class WebAssemblyFunction : public WebAssemblyFunctionBase {
     44class WebAssemblyFunction final : public WebAssemblyFunctionBase {
    4545public:
    4646    using Base = WebAssemblyFunctionBase;
    4747
    48     const static unsigned StructureFlags = Base::StructureFlags;
     48    const static unsigned StructureFlags = Base::StructureFlags | TypeOfShouldCallGetCallData;
    4949
    5050    DECLARE_EXPORT_INFO;
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.cpp

    r223002 r223274  
    8080{
    8181    ASSERT(globalObject);
    82     return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
     82    return Structure::create(vm, globalObject, prototype, TypeInfo(JSFunctionType, StructureFlags), info());
    8383}
    8484
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.h

    r217017 r223274  
    3333namespace JSC {
    3434
    35 class WebAssemblyWrapperFunction : public WebAssemblyFunctionBase {
     35class WebAssemblyWrapperFunction final : public WebAssemblyFunctionBase {
    3636public:
    3737    using Base = WebAssemblyFunctionBase;
Note: See TracChangeset for help on using the changeset viewer.