Changeset 272071 in webkit


Ignore:
Timestamp:
Jan 29, 2021 11:26:36 AM (18 months ago)
Author:
commit-queue@webkit.org
Message:

[JSC] WebAssembly.Global should support Funcref and Externref
https://bugs.webkit.org/show_bug.cgi?id=220914

Patch by Dmitry Bezhetskov <dbezhetskov> on 2021-01-29
Reviewed by Yusuke Suzuki.

JSTests:

Add tests for WebAssembly.Global ctors with
new reference types:
https://webassembly.github.io/reference-types/js-api/index.html#dom-global-global.

  • wasm/references/globals.js: Added.

(Pelmen):
(testGlobalConstructorForExternref):
(async testGlobalConstructorForFuncref):

Source/JavaScriptCore:

Allow using reference types in ctor of WebAssembly.Global
according to the spec
https://webassembly.github.io/reference-types/js-api/index.html#dom-global-global.

  • wasm/js/WebAssemblyGlobalConstructor.cpp:

(JSC::JSC_DEFINE_HOST_FUNCTION):

Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r272031 r272071  
     12021-01-29  Dmitry Bezhetskov  <dbezhetskov@igalia.com>
     2
     3        [JSC] WebAssembly.Global should support Funcref and Externref
     4        https://bugs.webkit.org/show_bug.cgi?id=220914
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Add tests for WebAssembly.Global ctors with
     9        new reference types:
     10        https://webassembly.github.io/reference-types/js-api/index.html#dom-global-global.
     11
     12        * wasm/references/globals.js: Added.
     13        (Pelmen):
     14        (testGlobalConstructorForExternref):
     15        (async testGlobalConstructorForFuncref):
     16
    1172021-01-28  Yusuke Suzuki  <ysuzuki@apple.com>
    218
  • trunk/Source/JavaScriptCore/ChangeLog

    r272064 r272071  
     12021-01-29  Dmitry Bezhetskov  <dbezhetskov@igalia.com>
     2
     3        [JSC] WebAssembly.Global should support Funcref and Externref
     4        https://bugs.webkit.org/show_bug.cgi?id=220914
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Allow using reference types in ctor of WebAssembly.Global
     9        according to the spec
     10        https://webassembly.github.io/reference-types/js-api/index.html#dom-global-global.
     11
     12        * wasm/js/WebAssemblyGlobalConstructor.cpp:
     13        (JSC::JSC_DEFINE_HOST_FUNCTION):
     14
    1152021-01-29  David Kilzer  <ddkilzer@apple.com>
    216
  • trunk/Source/JavaScriptCore/wasm/WasmTable.cpp

    r271303 r272071  
    175175}
    176176
     177Type Table::wasmType() const
     178{
     179    if (isExternrefTable())
     180        return Type::Externref;
     181    ASSERT(isFuncrefTable());
     182    return Type::Funcref;
     183}
     184
    177185FuncRefTable* Table::asFuncrefTable()
    178186{
  • trunk/Source/JavaScriptCore/wasm/WasmTable.h

    r271303 r272071  
    6969    bool isExternrefTable() const { return m_type == TableElementType::Externref; }
    7070    bool isFuncrefTable() const { return m_type == TableElementType::Funcref; }
     71    Type wasmType() const;
    7172    FuncRefTable* asFuncrefTable();
    7273
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h

    r271903 r272071  
    136136}
    137137
    138 ALWAYS_INLINE JSValue defaultValueForTable(const Wasm::TableElementType tableType)
     138ALWAYS_INLINE JSValue defaultValueForReferenceType(const Wasm::Type type)
    139139{
    140     if (tableType == Wasm::TableElementType::Externref)
     140    ASSERT(Wasm::isRefType(type));
     141    if (type == Wasm::Type::Externref)
    141142        return jsUndefined();
    142     ASSERT(tableType == Wasm::TableElementType::Funcref);
     143    ASSERT(type == Wasm::Type::Funcref);
    143144    return jsNull();
    144145}
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyGlobalConstructor.cpp

    r271168 r272071  
    3131#include "JSCInlines.h"
    3232#include "JSWebAssemblyGlobal.h"
     33#include "WasmFormat.h"
    3334#include "WebAssemblyGlobalPrototype.h"
    3435
     
    9495        else if (valueString == "f64")
    9596            type = Wasm::Type::F64;
     97        else if (Options::useWebAssemblyReferences() && valueString == "anyfunc")
     98            type = Wasm::Type::Funcref;
     99        else if (Options::useWebAssemblyReferences() && valueString == "externref")
     100            type = Wasm::Type::Externref;
    96101        else
    97102            return JSValue::encode(throwException(globalObject, throwScope, createTypeError(globalObject, "WebAssembly.Global expects its 'value' field to be the string 'i32', 'i64', 'f32', or 'f64'"_s)));
     
    126131            break;
    127132        }
     133        case Wasm::Type::Funcref:
     134        case Wasm::Type::Externref: {
     135            // We check default value for these types later in set method.
     136            ASSERT(Options::useWebAssemblyReferences());
     137            break;
     138        }
    128139        default:
    129140            RELEASE_ASSERT_NOT_REACHED();
     
    132143
    133144    Ref<Wasm::Global> wasmGlobal = Wasm::Global::create(type, mutability, initialValue);
    134     RELEASE_AND_RETURN(throwScope, JSValue::encode(JSWebAssemblyGlobal::tryCreate(globalObject, vm, webAssemblyGlobalStructure, WTFMove(wasmGlobal))));
     145    JSWebAssemblyGlobal* jsWebAssemblyGlobal = JSWebAssemblyGlobal::tryCreate(globalObject, vm, webAssemblyGlobalStructure, WTFMove(wasmGlobal));
     146    RETURN_IF_EXCEPTION(throwScope, { });
     147
     148    if (Wasm::isRefType(type)) {
     149        ASSERT(Options::useWebAssemblyReferences());
     150        if (argument.isUndefined())
     151            argument = defaultValueForReferenceType(type);
     152        jsWebAssemblyGlobal->global()->set(globalObject, argument);
     153        RETURN_IF_EXCEPTION(throwScope, { });
     154    }
     155    return JSValue::encode(jsWebAssemblyGlobal);
    135156}
    136157
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.cpp

    r271903 r272071  
    123123    if (Options::useWebAssemblyReferences()) {
    124124        JSValue defaultValue = callFrame->argumentCount() < 2
    125             ? defaultValueForTable(jsWebAssemblyTable->table()->type())
     125            ? defaultValueForReferenceType(jsWebAssemblyTable->table()->wasmType())
    126126            : callFrame->uncheckedArgument(1);
    127127        WebAssemblyFunction* wasmFunction = nullptr;
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp

    r271903 r272071  
    9595    if (Options::useWebAssemblyReferences()) {
    9696        if (callFrame->argumentCount() < 2)
    97             defaultValue = defaultValueForTable(table->table()->type());
     97            defaultValue = defaultValueForReferenceType(table->table()->wasmType());
    9898        else
    9999            defaultValue = callFrame->uncheckedArgument(1);
     
    141141    JSValue value = callFrame->argument(1);
    142142    if (Options::useWebAssemblyReferences() && callFrame->argumentCount() < 2)
    143         value = defaultValueForTable(table->table()->type());
     143        value = defaultValueForReferenceType(table->table()->wasmType());
    144144
    145145    if (table->table()->asFuncrefTable()) {
Note: See TracChangeset for help on using the changeset viewer.