Changeset 214484 in webkit


Ignore:
Timestamp:
Mar 28, 2017 11:41:53 AM (7 years ago)
Author:
jfbastien@apple.com
Message:

WebAssembly: implement Module imports/exports
https://bugs.webkit.org/show_bug.cgi?id=166982

Reviewed by Saam Barati.

JSTests:

  • wasm/js-api/Module.exports.js: Added.

(assert.throws.WebAssembly.Module.prototype.exports):
(assert.eq):

  • wasm/js-api/Module.imports.js: Added.

(assert.throws.WebAssembly.Module.prototype.imports):
(assert.eq):

Source/JavaScriptCore:

As defined in: https://github.com/WebAssembly/design/commit/18cbacb90cd3584dd5c9aa3d392e4e55f66af6ab

  • wasm/WasmFormat.h:

(JSC::Wasm::makeString): use uppercase instead, it was only used
for diagnostic but is now used for the expected JS property's
capitalization

  • wasm/js/WebAssemblyModulePrototype.cpp:

(JSC::webAssemblyModuleProtoImports):
(JSC::webAssemblyModuleProtoExports):

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r214438 r214484  
     12017-03-28  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: implement Module imports/exports
     4        https://bugs.webkit.org/show_bug.cgi?id=166982
     5
     6        Reviewed by Saam Barati.
     7
     8        * wasm/js-api/Module.exports.js: Added.
     9        (assert.throws.WebAssembly.Module.prototype.exports):
     10        (assert.eq):
     11        * wasm/js-api/Module.imports.js: Added.
     12        (assert.throws.WebAssembly.Module.prototype.imports):
     13        (assert.eq):
     14
    1152017-03-27  JF Bastien  <jfbastien@apple.com>
    216
  • trunk/Source/JavaScriptCore/ChangeLog

    r214465 r214484  
     12017-03-28  JF Bastien  <jfbastien@apple.com>
     2
     3        WebAssembly: implement Module imports/exports
     4        https://bugs.webkit.org/show_bug.cgi?id=166982
     5
     6        Reviewed by Saam Barati.
     7
     8        As defined in: https://github.com/WebAssembly/design/commit/18cbacb90cd3584dd5c9aa3d392e4e55f66af6ab
     9
     10        * wasm/WasmFormat.h:
     11        (JSC::Wasm::makeString): use uppercase instead, it was only used
     12        for diagnostic but is now used for the expected JS property's
     13        capitalization
     14        * wasm/js/WebAssemblyModulePrototype.cpp:
     15        (JSC::webAssemblyModuleProtoImports):
     16        (JSC::webAssemblyModuleProtoExports):
     17
    1182017-03-27  JF Bastien  <jfbastien@apple.com>
    219
  • trunk/Source/JavaScriptCore/wasm/WasmFormat.h

    r213465 r214484  
    11/*
    2  * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    9393{
    9494    switch (kind) {
    95     case ExternalKind::Function: return "Function";
    96     case ExternalKind::Table: return "Table";
    97     case ExternalKind::Memory: return "Memory";
    98     case ExternalKind::Global: return "Global";
     95    case ExternalKind::Function: return "function";
     96    case ExternalKind::Table: return "table";
     97    case ExternalKind::Memory: return "memory";
     98    case ExternalKind::Global: return "global";
    9999    }
    100100    RELEASE_ASSERT_NOT_REACHED();
  • trunk/Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.cpp

    r211247 r214484  
    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
     
    3434#include "JSCInlines.h"
    3535#include "JSWebAssemblyModule.h"
     36#include "ObjectConstructor.h"
    3637
    3738namespace JSC {
    3839static EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoCustomSections(ExecState*);
     40static EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoImports(ExecState*);
     41static EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoExports(ExecState*);
    3942}
    4043
     
    4851 @begin prototypeTableWebAssemblyModule
    4952 customSections webAssemblyModuleProtoCustomSections DontEnum|Function 1
     53 imports        webAssemblyModuleProtoImports        DontEnum|Accessor 0
     54 exports        webAssemblyModuleProtoExports        DontEnum|Accessor 0
    5055 @end
    5156 */
     
    5964    JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->thisValue());
    6065    if (!module)
    61         throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.prototype.customSections called with non WebAssembly.Module |this| value")));
    62     RETURN_IF_EXCEPTION(throwScope, { });
     66        return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.prototype.customSections called with non WebAssembly.Module |this| value"))));
    6367
    6468    const String sectionNameString = exec->argument(0).getString(exec);
     
    7377            auto buffer = ArrayBuffer::tryCreate(section.payload.data(), section.payload.size());
    7478            if (!buffer)
    75                 throwException(exec, throwScope, createOutOfMemoryError(exec));
     79                return JSValue::encode(throwException(exec, throwScope, createOutOfMemoryError(exec)));
    7680
    7781            Structure* arrayBufferStructure = InternalFunction::createSubclassStructure(exec, JSValue(), globalObject->arrayBufferStructure(ArrayBufferSharingMode::Default));
     
    7983
    8084            result->push(exec, JSArrayBuffer::create(vm, arrayBufferStructure, WTFMove(buffer)));
     85            RETURN_IF_EXCEPTION(throwScope, { });
     86        }
     87    }
     88
     89    return JSValue::encode(result);
     90}
     91
     92EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoImports(ExecState* exec)
     93{
     94    VM& vm = exec->vm();
     95    auto* globalObject = exec->lexicalGlobalObject();
     96    auto throwScope = DECLARE_THROW_SCOPE(vm);
     97
     98    JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->thisValue());
     99    if (!module)
     100        return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.prototype.imports called with non WebAssembly.Module |this| value"))));
     101
     102    JSArray* result = constructEmptyArray(exec, nullptr, globalObject);
     103    RETURN_IF_EXCEPTION(throwScope, { });
     104
     105    const auto& imports = module->moduleInformation().imports;
     106    if (imports.size()) {
     107        Identifier module = Identifier::fromString(exec, "module");
     108        Identifier name = Identifier::fromString(exec, "name");
     109        Identifier kind = Identifier::fromString(exec, "kind");
     110        for (const Wasm::Import& imp : imports) {
     111            JSObject* obj = constructEmptyObject(exec);
     112            RETURN_IF_EXCEPTION(throwScope, { });
     113            obj->putDirect(vm, module, jsString(exec, imp.module.string()));
     114            obj->putDirect(vm, name, jsString(exec, imp.field.string()));
     115            obj->putDirect(vm, kind, jsString(exec, String(makeString(imp.kind))));
     116            result->push(exec, obj);
     117            RETURN_IF_EXCEPTION(throwScope, { });
     118        }
     119    }
     120
     121    return JSValue::encode(result);
     122}
     123
     124EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoExports(ExecState* exec)
     125{
     126    VM& vm = exec->vm();
     127    auto* globalObject = exec->lexicalGlobalObject();
     128    auto throwScope = DECLARE_THROW_SCOPE(vm);
     129
     130    JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->thisValue());
     131    if (!module)
     132        return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.prototype.exports called with non WebAssembly.Module |this| value"))));
     133
     134    JSArray* result = constructEmptyArray(exec, nullptr, globalObject);
     135    RETURN_IF_EXCEPTION(throwScope, { });
     136
     137    const auto& exports = module->moduleInformation().exports;
     138    if (exports.size()) {
     139        Identifier name = Identifier::fromString(exec, "name");
     140        Identifier kind = Identifier::fromString(exec, "kind");
     141        for (const Wasm::Export& exp : exports) {
     142            JSObject* obj = constructEmptyObject(exec);
     143            RETURN_IF_EXCEPTION(throwScope, { });
     144            obj->putDirect(vm, name, jsString(exec, exp.field.string()));
     145            obj->putDirect(vm, kind, jsString(exec, String(makeString(exp.kind))));
     146            result->push(exec, obj);
    81147            RETURN_IF_EXCEPTION(throwScope, { });
    82148        }
Note: See TracChangeset for help on using the changeset viewer.