Changeset 217097 in webkit


Ignore:
Timestamp:
May 18, 2017 10:27:28 PM (7 years ago)
Author:
jfbastien@apple.com
Message:

WebAssembly: exports is a getter
https://bugs.webkit.org/show_bug.cgi?id=172129

Reviewed by Saam Barati.

JSTests:

Update test to reflect new semantics.

  • wasm/js-api/test_basic_api.js:

(const.c.in.constructorProperties.switch):

Source/JavaScriptCore:

As updated here: https://github.com/WebAssembly/design/pull/1062

  • wasm/js/JSWebAssemblyInstance.cpp:

(JSC::JSWebAssemblyInstance::finishCreation): don't putDirect here anymore

  • wasm/js/JSWebAssemblyInstance.h:

(JSC::JSWebAssemblyInstance::moduleNamespaceObject): add accessor

  • wasm/js/WebAssemblyFunctionBase.cpp: squelch causing a warning
  • wasm/js/WebAssemblyInstancePrototype.cpp: use LUT

(JSC::getInstance): helper, as in surrounding files
(JSC::webAssemblyInstanceProtoFuncExports): instead of putDirect

  • wasm/js/WebAssemblyMemoryPrototype.cpp: pass VM around as for Table

(JSC::getMemory):
(JSC::webAssemblyMemoryProtoFuncGrow):
(JSC::webAssemblyMemoryProtoFuncBuffer):

  • wasm/js/WebAssemblyTablePrototype.cpp: static everywhere as with other code

(JSC::webAssemblyTableProtoFuncLength):
(JSC::webAssemblyTableProtoFuncGrow):
(JSC::webAssemblyTableProtoFuncGet):
(JSC::webAssemblyTableProtoFuncSet):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r217093 r217097  
     12017-05-18  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: exports is a getter
     4        https://bugs.webkit.org/show_bug.cgi?id=172129
     5
     6        Reviewed by Saam Barati.
     7
     8        Update test to reflect new semantics.
     9
     10        * wasm/js-api/test_basic_api.js:
     11        (const.c.in.constructorProperties.switch):
     12
    1132017-05-18  Saam Barati  <sbarati@apple.com>
    214
  • trunk/JSTests/wasm/js-api/test_basic_api.js

    r217052 r217097  
    1111    assert.eq(typeof descriptor.value, expect.typeofvalue);
    1212    assert.eq(descriptor.writable, expect.writable);
     13    assert.eq(descriptor.configurable, expect.configurable);
     14    assert.eq(descriptor.enumerable, expect.enumerable);
     15};
     16
     17const checkAccessorOwnPropertyDescriptor = (obj, prop, expect) => {
     18    const descriptor = Object.getOwnPropertyDescriptor(obj, prop);
     19    assert.eq(typeof descriptor.value, "undefined");
     20    assert.eq(typeof descriptor.writable, "undefined");
    1321    assert.eq(descriptor.configurable, expect.configurable);
    1422    assert.eq(descriptor.enumerable, expect.enumerable);
     
    7179            assert.throws(() => new WebAssembly[c](new WebAssembly.Module(emptyModuleArray), invalid), TypeError, `second argument to WebAssembly.Instance must be undefined or an Object (evaluating 'new WebAssembly[c](new WebAssembly.Module(emptyModuleArray), invalid)')`);
    7280        assert.isNotUndef(instance.exports);
    73         checkOwnPropertyDescriptor(instance, "exports", { typeofvalue: "object", writable: true, configurable: true, enumerable: true });
     81        checkAccessorOwnPropertyDescriptor(WebAssembly.Instance.prototype, "exports", { configurable: true, enumerable: false });
     82        assert.throws(() => WebAssembly.Instance.prototype.exports = undefined, TypeError, `Attempted to assign to readonly property.`);
     83        assert.throws(() => WebAssembly.Instance.prototype.exports, TypeError, `expected |this| value to be an instance of WebAssembly.Instance`);
    7484        assert.isUndef(instance.exports.__proto__);
    7585        assert.eq(Reflect.isExtensible(instance.exports), false);
  • trunk/Source/JavaScriptCore/ChangeLog

    r217093 r217097  
     12017-05-18  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: exports is a getter
     4        https://bugs.webkit.org/show_bug.cgi?id=172129
     5
     6        Reviewed by Saam Barati.
     7
     8        As updated here: https://github.com/WebAssembly/design/pull/1062
     9
     10        * wasm/js/JSWebAssemblyInstance.cpp:
     11        (JSC::JSWebAssemblyInstance::finishCreation): don't putDirect here anymore
     12        * wasm/js/JSWebAssemblyInstance.h:
     13        (JSC::JSWebAssemblyInstance::moduleNamespaceObject): add accessor
     14        * wasm/js/WebAssemblyFunctionBase.cpp: squelch causing a warning
     15        * wasm/js/WebAssemblyInstancePrototype.cpp: use LUT
     16        (JSC::getInstance): helper, as in surrounding files
     17        (JSC::webAssemblyInstanceProtoFuncExports): instead of putDirect
     18        * wasm/js/WebAssemblyMemoryPrototype.cpp: pass VM around as for Table
     19        (JSC::getMemory):
     20        (JSC::webAssemblyMemoryProtoFuncGrow):
     21        (JSC::webAssemblyMemoryProtoFuncBuffer):
     22        * wasm/js/WebAssemblyTablePrototype.cpp: static everywhere as with other code
     23        (JSC::webAssemblyTableProtoFuncLength):
     24        (JSC::webAssemblyTableProtoFuncGrow):
     25        (JSC::webAssemblyTableProtoFuncGet):
     26        (JSC::webAssemblyTableProtoFuncSet):
     27
    1282017-05-18  Saam Barati  <sbarati@apple.com>
    229
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp

    r217049 r217097  
    7070    m_moduleNamespaceObject.set(vm, this, moduleNamespaceObject);
    7171    m_callee.set(vm, this, module->callee());
    72     putDirect(vm, Identifier::fromString(&vm, "exports"), moduleNamespaceObject, None);
    7372}
    7473
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h

    r217060 r217097  
    5555
    5656    JSObject* importFunction(unsigned idx) { RELEASE_ASSERT(idx < m_numImportFunctions); return importFunctions()[idx].get(); }
     57
     58    JSModuleNamespaceObject* moduleNamespaceObject() { return m_moduleNamespaceObject.get(); }
    5759
    5860    JSWebAssemblyMemory* memory() { return m_memory.get(); }
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.cpp

    r217049 r217097  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3131#include "FunctionPrototype.h"
    3232#include "JSCInlines.h"
     33#include "JSModuleNamespaceObject.h"
     34#include "JSWebAssemblyInstance.h"
     35
     36namespace JSC {
     37static EncodedJSValue JSC_HOST_CALL webAssemblyInstanceProtoFuncExports(ExecState*);
     38}
    3339
    3440#include "WebAssemblyInstancePrototype.lut.h"
     
    4046/* Source for WebAssemblyInstancePrototype.lut.h
    4147 @begin prototypeTableWebAssemblyInstance
     48 exports webAssemblyInstanceProtoFuncExports DontEnum|Accessor 0
    4249 @end
    4350 */
     51
     52static ALWAYS_INLINE JSWebAssemblyInstance* getInstance(ExecState* exec, VM& vm, JSValue v)
     53{
     54    auto throwScope = DECLARE_THROW_SCOPE(vm);
     55    JSWebAssemblyInstance* result = jsDynamicCast<JSWebAssemblyInstance*>(vm, v);
     56    if (!result) {
     57        throwException(exec, throwScope,
     58            createTypeError(exec, ASCIILiteral("expected |this| value to be an instance of WebAssembly.Instance")));
     59        return nullptr;
     60    }
     61    return result;
     62}
     63
     64static EncodedJSValue JSC_HOST_CALL webAssemblyInstanceProtoFuncExports(ExecState* exec)
     65{
     66    VM& vm = exec->vm();
     67    auto throwScope = DECLARE_THROW_SCOPE(vm);
     68
     69    JSWebAssemblyInstance* instance = getInstance(exec, vm, exec->thisValue());
     70    RETURN_IF_EXCEPTION(throwScope, { });
     71    return JSValue::encode(instance->moduleNamespaceObject());
     72}
    4473
    4574WebAssemblyInstancePrototype* WebAssemblyInstancePrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp

    r217049 r217097  
    5454*/
    5555
    56 ALWAYS_INLINE JSWebAssemblyMemory* getMemory(ExecState* exec, JSValue value)
     56ALWAYS_INLINE JSWebAssemblyMemory* getMemory(ExecState* exec, VM& vm, JSValue value)
    5757{
    58     VM& vm = exec->vm();
    5958    auto throwScope = DECLARE_THROW_SCOPE(vm);
    6059
     
    7372    auto throwScope = DECLARE_THROW_SCOPE(vm);
    7473
    75     JSWebAssemblyMemory* memory = getMemory(exec, exec->thisValue());
     74    JSWebAssemblyMemory* memory = getMemory(exec, vm, exec->thisValue());
    7675    RETURN_IF_EXCEPTION(throwScope, { });
    7776   
     
    9190    auto throwScope = DECLARE_THROW_SCOPE(vm);
    9291
    93     JSWebAssemblyMemory* memory = getMemory(exec, exec->thisValue());
     92    JSWebAssemblyMemory* memory = getMemory(exec, vm, exec->thisValue());
    9493    RETURN_IF_EXCEPTION(throwScope, { });
    9594    return JSValue::encode(memory->buffer(exec->vm(), exec->lexicalGlobalObject()));
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp

    r217049 r217097  
    6868}
    6969
    70 EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState* exec)
     70static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState* exec)
    7171{
    7272    VM& vm = exec->vm();
     
    7878}
    7979
    80 EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState* exec)
     80static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState* exec)
    8181{
    8282    VM& vm = exec->vm();
     
    9494}
    9595
    96 EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState* exec)
     96static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState* exec)
    9797{
    9898    VM& vm = exec->vm();
     
    112112}
    113113
    114 EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec)
     114static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec)
    115115{
    116116    VM& vm = exec->vm();
Note: See TracChangeset for help on using the changeset viewer.