Changeset 214547 in webkit


Ignore:
Timestamp:
Mar 29, 2017 10:44:59 AM (7 years ago)
Author:
jfbastien@apple.com
Message:

WebAssembly: add shell-only Memory mode helper
https://bugs.webkit.org/show_bug.cgi?id=170227

Reviewed by Mark Lam.

JSTests:

  • wasm/assert.js: fix a prior debug thing I forgot to remove
  • wasm/function-tests/memory-section-and-import.js: the assert

issue was hiding a failure in error message here

  • wasm/js-api/element.js: the assert issue was hiding a failure in

error message here
(badInstantiation.test):
(badInstantiation):

  • wasm/js-api/extension-MemoryMode.js: Added.

(const.validateMode.what.switch):
(testMemoryNoMax):
(testMemory):
(testInstanceNoMemory):
(testInstanceNoMax):
(testInstance):

  • wasm/js-api/test_memory.js: the assert issue was hiding a

failure in error message here
(test):

Source/JavaScriptCore:

  • jsc.cpp:

(GlobalObject::finishCreation):
(functionWebAssemblyMemoryMode):

  • wasm/WasmMemory.h:
  • wasm/js/JSWebAssemblyInstance.h:
  • wasm/js/JSWebAssemblyMemory.h:
Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r214504 r214547  
     12017-03-29  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: add shell-only Memory mode helper
     4        https://bugs.webkit.org/show_bug.cgi?id=170227
     5
     6        Reviewed by Mark Lam.
     7
     8        * wasm/assert.js: fix a prior debug thing I forgot to remove
     9        * wasm/function-tests/memory-section-and-import.js: the assert
     10        issue was hiding a failure in error message here
     11        * wasm/js-api/element.js: the assert issue was hiding a failure in
     12        error message here
     13        (badInstantiation.test):
     14        (badInstantiation):
     15        * wasm/js-api/extension-MemoryMode.js: Added.
     16        (const.validateMode.what.switch):
     17        (testMemoryNoMax):
     18        (testMemory):
     19        (testInstanceNoMemory):
     20        (testInstanceNoMax):
     21        (testInstance):
     22        * wasm/js-api/test_memory.js: the assert issue was hiding a
     23        failure in error message here
     24        (test):
     25
    1262017-03-28  Keith Miller  <keith_miller@apple.com>
    227
  • trunk/JSTests/wasm/assert.js

    r214504 r214547  
    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
     
    4646export const notNumber = (v, msg) => isNotA(v, "number", msg);
    4747export const isNumber = (v, msg) => isA(v, "number", msg);
     48export const notFunction = (v, msg) => isNotA(v, "function", msg);
     49export const isFunction = (v, msg) => isA(v, "function", msg);
    4850
    4951export const hasObjectProperty = (o, p, msg) => {
     
    128130                    return e;
    129131            }
    130             return e;
    131132        }
    132133        _fail(`Expected to throw a ${type.name} with message "${message}", got ${e.name} with message "${e.message}"`);
  • trunk/JSTests/wasm/function-tests/memory-section-and-import.js

    r214438 r214547  
    2929
    3030const i0 = instantiate(builder0);
    31 assert.throws(() => instantiate(builder1, { imp: { memory: i0.exports.memory } }), WebAssembly.CompileError, `WebAssembly.Module doesn't parse at byte 34 / 40: Memory section cannot exist if an Import has a memory`);
     31assert.throws(() => instantiate(builder1, { imp: { memory: i0.exports.memory } }), WebAssembly.CompileError, `WebAssembly.Module doesn't parse at byte 35 / 41: Memory section cannot exist if an Import has a memory`);
  • trunk/JSTests/wasm/js-api/element.js

    r213484 r214547  
    182182                assert.eq(table.get(j)(i*2), i*2 + 42);
    183183            else
    184                 assert.throws(() => table.get(j)(i*2), TypeError, "table.get(j) is not a function.");
     184                assert.throws(() => table.get(j)(i*2), TypeError, "table.get(j) is not a function. (In 'table.get(j)(i*2)', 'table.get(j)' is null)");
    185185        }
    186186    }
  • trunk/JSTests/wasm/js-api/test_memory.js

    r210201 r214547  
    318318    const module = new WebAssembly.Module(bin);
    319319
    320     assert.throws(() => new WebAssembly.Instance(module, 20), TypeError, `second argument to WebAssembly.Instance must be undefined or an Object (evaluating 'new WebAssembly.Instance(module, 20)')`);
    321     assert.throws(() => new WebAssembly.Instance(module, {}), TypeError, `import must be an object (evaluating 'new WebAssembly.Instance(module, {})')`);
    322     assert.throws(() => new WebAssembly.Instance(module, {imp: { } }), WebAssembly.LinkError, `Memory import is not an instance of WebAssembly.Memory (evaluating 'new WebAssembly.Instance(module, {imp: { } })')`);
    323     assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: 20 } }), WebAssembly.LinkError, `Memory import is not an instance of WebAssembly.Memory (evaluating 'new WebAssembly.Instance(module, {imp: { memory: 20 } })')`);
    324     assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: [] } }), WebAssembly.LinkError, `Memory import is not an instance of WebAssembly.Memory (evaluating 'new WebAssembly.Instance(module, {imp: { memory: [] } })')`);
    325     assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } }), WebAssembly.LinkError, `Memory import provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } })')`);
    326     assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20}) } }), WebAssembly.LinkError, `Memory import did not have a 'maximum' but the module requires that it does (evaluating 'new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20}) } })')`);
    327     assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20, maximum: 26}) } }), WebAssembly.LinkError, `Memory imports 'maximum' is larger than the module's expected 'maximum' (evaluating 'new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20, maximum: 26}) } })')`);
     320    assert.throws(() => new WebAssembly.Instance(module, 20), TypeError, `second argument to WebAssembly.Instance must be undefined or an Object`);
     321    assert.throws(() => new WebAssembly.Instance(module, {}), TypeError, `import must be an object`);
     322    assert.throws(() => new WebAssembly.Instance(module, {imp: { } }), WebAssembly.LinkError, `Memory import is not an instance of WebAssembly.Memory`);
     323    assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: 20 } }), WebAssembly.LinkError, `Memory import is not an instance of WebAssembly.Memory`);
     324    assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: [] } }), WebAssembly.LinkError, `Memory import is not an instance of WebAssembly.Memory`);
     325    assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } }), WebAssembly.LinkError, `Memory import provided an 'initial' that is smaller than the module's declared 'initial' import memory size`);
     326    assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20}) } }), WebAssembly.LinkError, `Memory import did not have a 'maximum' but the module requires that it does`);
     327    assert.throws(() => new WebAssembly.Instance(module, {imp: { memory: new WebAssembly.Memory({initial: 20, maximum: 26}) } }), WebAssembly.LinkError, `Memory import provided a 'maximum' that is larger than the module's declared 'maximum' import memory size`);
    328328});
    329329
     
    355355    }
    356356
    357     testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } }, "Memory import provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, instanceObj)')");
    358     testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 19}) } }, "Memory import provided an 'initial' that is too small (evaluating 'new WebAssembly.Instance(module, instanceObj)')");
     357    testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 19, maximum: 25}) } }, `Memory import provided an 'initial' that is smaller than the module's declared 'initial' import memory size`);
     358    testMemImportError({imp: { memory: new WebAssembly.Memory({initial: 19}) } }, `Memory import provided an 'initial' that is smaller than the module's declared 'initial' import memory size`);
    359359
    360360    // This should not throw.
  • trunk/Source/JavaScriptCore/ChangeLog

    r214544 r214547  
     12017-03-29  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: add shell-only Memory mode helper
     4        https://bugs.webkit.org/show_bug.cgi?id=170227
     5
     6        Reviewed by Mark Lam.
     7
     8        * jsc.cpp:
     9        (GlobalObject::finishCreation):
     10        (functionWebAssemblyMemoryMode):
     11        * wasm/WasmMemory.h:
     12        * wasm/js/JSWebAssemblyInstance.h:
     13        * wasm/js/JSWebAssemblyMemory.h:
     14
    1152017-03-29  Keith Miller  <keith_miller@apple.com>
    216
  • trunk/Source/JavaScriptCore/jsc.cpp

    r214504 r214547  
    5858#include "JSTypedArrays.h"
    5959#include "JSWebAssemblyCallee.h"
     60#include "JSWebAssemblyInstance.h"
     61#include "JSWebAssemblyMemory.h"
    6062#include "LLIntData.h"
    6163#include "LLIntThunks.h"
     
    10851087#if ENABLE(WEBASSEMBLY)
    10861088static EncodedJSValue JSC_HOST_CALL functionTestWasmModuleFunctions(ExecState*);
     1089static EncodedJSValue JSC_HOST_CALL functionWebAssemblyMemoryMode(ExecState*);
    10871090#endif
    10881091
     
    13591362#if ENABLE(WEBASSEMBLY)
    13601363        addFunction(vm, "testWasmModuleFunctions", functionTestWasmModuleFunctions, 0);
     1364        addFunction(vm, "WebAssemblyMemoryMode", functionWebAssemblyMemoryMode, 1);
    13611365#endif
    13621366
     
    32473251}
    32483252
     3253static EncodedJSValue JSC_HOST_CALL functionWebAssemblyMemoryMode(ExecState* exec)
     3254{
     3255    VM& vm = exec->vm();
     3256    auto scope = DECLARE_THROW_SCOPE(vm);
     3257   
     3258    if (!Options::useWebAssembly())
     3259        return throwVMTypeError(exec, scope, ASCIILiteral("WebAssemblyMemoryMode should only be called if the useWebAssembly option is set"));
     3260
     3261    if (JSObject* object = exec->argument(0).getObject()) {
     3262        if (auto* memory = jsDynamicCast<JSWebAssemblyMemory*>(vm, object))
     3263            return JSValue::encode(jsString(&vm, makeString(memory->memory().mode())));
     3264        if (auto* instance = jsDynamicCast<JSWebAssemblyInstance*>(vm, object))
     3265            return JSValue::encode(jsString(&vm, makeString(instance->memoryMode())));
     3266    }
     3267
     3268    return throwVMTypeError(exec, scope, ASCIILiteral("WebAssemblyMemoryMode expects either a WebAssembly.Memory or WebAssembly.Instance"));
     3269}
     3270
    32493271#endif // ENABLE(WEBASSEBLY)
    32503272
  • trunk/Source/JavaScriptCore/wasm/WasmMemory.h

    r214504 r214547  
    5252};
    5353static constexpr size_t NumberOfMemoryModes = static_cast<size_t>(MemoryMode::NumberOfMemoryModes);
    54 const char* makeString(MemoryMode);
     54JS_EXPORT_PRIVATE const char* makeString(MemoryMode);
    5555
    5656class Memory : public RefCounted<Memory> {
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h

    r214504 r214547  
    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
     
    5252    static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
    5353
    54     DECLARE_INFO;
     54    DECLARE_EXPORT_INFO;
    5555
    5656    JSWebAssemblyCodeBlock* codeBlock() const { return m_codeBlock.get(); }
  • trunk/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h

    r213386 r214547  
    4545    static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
    4646
    47     DECLARE_INFO;
     47    DECLARE_EXPORT_INFO;
    4848
    4949    Wasm::Memory& memory() { return m_memory.get(); }
Note: See TracChangeset for help on using the changeset viewer.