| Differences between
and this patch
- a/Source/JavaScriptCore/ChangeLog +35 lines
Lines 1-3 a/Source/JavaScriptCore/ChangeLog_sec1
1
2017-03-28  JF Bastien  <jfbastien@apple.com>
2
3
        WebAssembly: fix misc JS API implementation inconsistencies
4
        https://bugs.webkit.org/show_bug.cgi?id=170187
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        * wasm/JSWebAssembly.cpp: validate / compile / instantiate should
9
        be on the prototype
10
        (JSC::JSWebAssembly::create):
11
        (JSC::JSWebAssembly::finishCreation):
12
        (JSC::webAssemblyCompileFunc): Deleted.
13
        (JSC::webAssemblyInstantiateFunc): Deleted.
14
        (JSC::webAssemblyValidateFunc): Deleted.
15
        * wasm/JSWebAssembly.h:
16
        * wasm/js/WebAssemblyMemoryPrototype.cpp: move validate / compile
17
        / instantiate here, and use auto-generated lookup tables
18
        (JSC::webAssemblyMemoryProtoFuncBuffer):
19
        (JSC::WebAssemblyMemoryPrototype::create):
20
        (JSC::WebAssemblyMemoryPrototype::finishCreation):
21
        * wasm/js/WebAssemblyMemoryPrototype.h:
22
        * wasm/js/WebAssemblyPrototype.cpp: use auto-generated lookup tables
23
        (JSC::webAssemblyValidateFunc):
24
        (JSC::webAssemblyCompileFunc):
25
        (JSC::webAssemblyInstantiateFunc):
26
        (JSC::webAssemblyFunctionValidate): Deleted.
27
        (JSC::webAssemblyFunctionCompile): Deleted.
28
        * wasm/js/WebAssemblyTablePrototype.cpp: make exception return idiomatic
29
        (JSC::webAssemblyTableProtoFuncGrow):
30
        (JSC::webAssemblyTableProtoFuncGet):
31
        (JSC::webAssemblyTableProtoFuncSet):
32
        (JSC::WebAssemblyTablePrototype::create):
33
        (JSC::WebAssemblyTablePrototype::finishCreation):
34
        * wasm/js/WebAssemblyTablePrototype.h:
35
1
2017-03-27  JF Bastien  <jfbastien@apple.com>
36
2017-03-27  JF Bastien  <jfbastien@apple.com>
2
37
3
        WebAssembly: JSWebAssemblyCodeBlock.h belongs in JavaScriptCore/wasm/js not JavaScriptCore/wasm
38
        WebAssembly: JSWebAssemblyCodeBlock.h belongs in JavaScriptCore/wasm/js not JavaScriptCore/wasm
- a/Source/JavaScriptCore/wasm/JSWebAssembly.cpp -110 / +6 lines
Lines 1-5 a/Source/JavaScriptCore/wasm/JSWebAssembly.cpp_sec1
1
/*
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
2
 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 28-146 a/Source/JavaScriptCore/wasm/JSWebAssembly.cpp_sec2
28
28
29
#if ENABLE(WEBASSEMBLY)
29
#if ENABLE(WEBASSEMBLY)
30
30
31
#include "Exception.h"
32
#include "FunctionPrototype.h"
33
#include "JSCInlines.h"
31
#include "JSCInlines.h"
34
#include "JSPromiseDeferred.h"
35
#include "JSWebAssemblyHelpers.h"
36
#include "ObjectConstructor.h"
37
#include "WasmPlan.h"
38
#include "WebAssemblyModuleConstructor.h"
39
32
40
namespace JSC {
33
namespace JSC {
41
34
42
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSWebAssembly);
43
44
EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState*);
45
EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState*);
46
EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState*);
47
48
EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState* exec)
49
{
50
    VM& vm = exec->vm();
51
    auto catchScope = DECLARE_CATCH_SCOPE(vm);
52
53
    JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, exec->lexicalGlobalObject());
54
    RETURN_IF_EXCEPTION(catchScope, encodedJSValue());
55
56
    // FIXME: Make this truly asynchronous:
57
    // https://bugs.webkit.org/show_bug.cgi?id=166016
58
    JSValue module = WebAssemblyModuleConstructor::createModule(exec, exec->argument(0), exec->lexicalGlobalObject()->WebAssemblyModuleStructure());
59
    if (Exception* exception = catchScope.exception()) {
60
        catchScope.clearException();
61
        promise->reject(exec, exception->value());
62
        return JSValue::encode(promise->promise());
63
    }
64
65
    promise->resolve(exec, module);
66
    return JSValue::encode(promise->promise());
67
}
68
69
EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState* exec)
70
{
71
    VM& vm = exec->vm();
72
    auto catchScope = DECLARE_CATCH_SCOPE(vm);
73
74
    // FIXME: Make this API truly asynchronous: https://bugs.webkit.org/show_bug.cgi?id=169187
75
76
    JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, exec->lexicalGlobalObject());
77
    RETURN_IF_EXCEPTION(catchScope, encodedJSValue());
78
79
    auto reject = [&] () {
80
        Exception* exception = catchScope.exception();
81
        ASSERT(exception);
82
        catchScope.clearException();
83
        promise->reject(exec, exception->value());
84
        return JSValue::encode(promise->promise());
85
    };
86
87
    JSValue importArgument = exec->argument(1);
88
    JSObject* importObject = importArgument.getObject();
89
    if (!importArgument.isUndefined() && !importObject) {
90
        promise->reject(exec, createTypeError(exec,
91
            ASCIILiteral("second argument to WebAssembly.instantiate must be undefined or an Object"), defaultSourceAppender, runtimeTypeForValue(importArgument)));
92
        return JSValue::encode(promise->promise());
93
    }
94
95
    JSValue firstArgument = exec->argument(0);
96
    JSValue module;
97
    bool firstArgumentIsModule = false;
98
    if (firstArgument.inherits(vm, JSWebAssemblyModule::info())) {
99
        firstArgumentIsModule = true;
100
        module = firstArgument;
101
    } else {
102
        module = WebAssemblyModuleConstructor::createModule(exec, firstArgument, exec->lexicalGlobalObject()->WebAssemblyModuleStructure());
103
        if (catchScope.exception())
104
            return reject();
105
    }
106
107
    JSWebAssemblyInstance* instance = WebAssemblyInstanceConstructor::createInstance(exec, jsCast<JSWebAssemblyModule*>(module), importObject, exec->lexicalGlobalObject()->WebAssemblyInstanceStructure());
108
    if (catchScope.exception())
109
        return reject();
110
111
    if (firstArgumentIsModule)
112
        promise->resolve(exec, instance);
113
    else {
114
        JSObject* result = constructEmptyObject(exec);
115
        result->putDirect(vm, Identifier::fromString(&vm, ASCIILiteral("module")), module);
116
        result->putDirect(vm, Identifier::fromString(&vm, ASCIILiteral("instance")), instance);
117
        promise->resolve(exec, result);
118
    }
119
120
    return JSValue::encode(promise->promise());
121
}
122
123
EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState* exec)
124
{
125
    VM& vm = exec->vm();
126
    auto scope = DECLARE_THROW_SCOPE(vm);
127
128
    size_t byteOffset;
129
    size_t byteSize;
130
    uint8_t* base = getWasmBufferFromValue(exec, exec->argument(0), byteOffset, byteSize);
131
    RETURN_IF_EXCEPTION(scope, encodedJSValue());
132
    Wasm::Plan plan(&vm, base + byteOffset, byteSize);
133
    // FIXME: We might want to throw an OOM exception here if we detect that something will OOM.
134
    // https://bugs.webkit.org/show_bug.cgi?id=166015
135
    return JSValue::encode(jsBoolean(plan.parseAndValidateModule()));
136
}
137
138
const ClassInfo JSWebAssembly::s_info = { "WebAssembly", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssembly) };
35
const ClassInfo JSWebAssembly::s_info = { "WebAssembly", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssembly) };
139
36
140
JSWebAssembly* JSWebAssembly::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
37
STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSWebAssembly);
38
39
JSWebAssembly* JSWebAssembly::create(VM& vm, JSGlobalObject*, Structure* structure)
141
{
40
{
142
    auto* object = new (NotNull, allocateCell<JSWebAssembly>(vm.heap)) JSWebAssembly(vm, structure);
41
    auto* object = new (NotNull, allocateCell<JSWebAssembly>(vm.heap)) JSWebAssembly(vm, structure);
143
    object->finishCreation(vm, globalObject);
42
    object->finishCreation(vm);
144
    return object;
43
    return object;
145
}
44
}
146
45
Lines 149-161 Structure* JSWebAssembly::createStructure(VM& vm, JSGlobalObject* globalObject, a/Source/JavaScriptCore/wasm/JSWebAssembly.cpp_sec3
149
    return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
48
    return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
150
}
49
}
151
50
152
void JSWebAssembly::finishCreation(VM& vm, JSGlobalObject* globalObject)
51
void JSWebAssembly::finishCreation(VM& vm)
153
{
52
{
154
    Base::finishCreation(vm);
53
    Base::finishCreation(vm);
155
    ASSERT(inherits(vm, info()));
54
    ASSERT(inherits(vm, info()));
156
    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("validate", webAssemblyValidateFunc, DontEnum, 1);
157
    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("compile", webAssemblyCompileFunc, DontEnum, 1);
158
    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("instantiate", webAssemblyInstantiateFunc, DontEnum, 1);
159
}
55
}
160
56
161
JSWebAssembly::JSWebAssembly(VM& vm, Structure* structure)
57
JSWebAssembly::JSWebAssembly(VM& vm, Structure* structure)
- a/Source/JavaScriptCore/wasm/JSWebAssembly.h -2 / +2 lines
Lines 1-5 a/Source/JavaScriptCore/wasm/JSWebAssembly.h_sec1
1
/*
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
2
 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 67-73 public: a/Source/JavaScriptCore/wasm/JSWebAssembly.h_sec2
67
    DECLARE_INFO;
67
    DECLARE_INFO;
68
68
69
protected:
69
protected:
70
    void finishCreation(VM&, JSGlobalObject*);
70
    void finishCreation(VM&);
71
71
72
private:
72
private:
73
    JSWebAssembly(VM&, Structure*);
73
    JSWebAssembly(VM&, Structure*);
- a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp -18 / +18 lines
Lines 1-5 a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp_sec1
1
/*
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
2
 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 36-41 a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp_sec2
36
36
37
namespace JSC {
37
namespace JSC {
38
static EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState*);
38
static EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState*);
39
static EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState*);
39
}
40
}
40
41
41
#include "WebAssemblyMemoryPrototype.lut.h"
42
#include "WebAssemblyMemoryPrototype.lut.h"
Lines 47-58 const ClassInfo WebAssemblyMemoryPrototype::s_info = { "WebAssembly.Memory.proto a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp_sec3
47
48
48
/* Source for WebAssemblyMemoryPrototype.lut.h
49
/* Source for WebAssemblyMemoryPrototype.lut.h
49
@begin prototypeTableWebAssemblyMemory
50
@begin prototypeTableWebAssemblyMemory
50
  grow     webAssemblyMemoryProtoFuncGrow   DontEnum|Function 1
51
 grow   webAssemblyMemoryProtoFuncGrow   DontEnum|Function 1
52
 buffer webAssemblyMemoryProtoFuncBuffer DontEnum|Accessor 0
51
@end
53
@end
52
*/
54
*/
53
55
54
EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState*);
55
56
ALWAYS_INLINE JSWebAssemblyMemory* getMemory(ExecState* exec, JSValue value)
56
ALWAYS_INLINE JSWebAssemblyMemory* getMemory(ExecState* exec, JSValue value)
57
{
57
{
58
    VM& vm = exec->vm();
58
    VM& vm = exec->vm();
Lines 67-82 ALWAYS_INLINE JSWebAssemblyMemory* getMemory(ExecState* exec, JSValue value) a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp_sec4
67
    return memory;
67
    return memory;
68
}
68
}
69
69
70
EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState* exec)
71
{
72
    VM& vm = exec->vm();
73
    auto throwScope = DECLARE_THROW_SCOPE(vm);
74
75
    JSWebAssemblyMemory* memory = getMemory(exec, exec->thisValue()); 
76
    RETURN_IF_EXCEPTION(throwScope, { });
77
    return JSValue::encode(memory->buffer(exec->vm(), exec->lexicalGlobalObject()));
78
}
79
80
EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState* exec)
70
EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState* exec)
81
{
71
{
82
    VM& vm = exec->vm();
72
    VM& vm = exec->vm();
Lines 95-104 EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState* exec) a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp_sec5
95
    return JSValue::encode(jsNumber(result.pageCount()));
85
    return JSValue::encode(jsNumber(result.pageCount()));
96
}
86
}
97
87
98
WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
88
EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState* exec)
89
{
90
    VM& vm = exec->vm();
91
    auto throwScope = DECLARE_THROW_SCOPE(vm);
92
93
    JSWebAssemblyMemory* memory = getMemory(exec, exec->thisValue()); 
94
    RETURN_IF_EXCEPTION(throwScope, { });
95
    return JSValue::encode(memory->buffer(exec->vm(), exec->lexicalGlobalObject()));
96
}
97
98
WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
99
{
99
{
100
    auto* object = new (NotNull, allocateCell<WebAssemblyMemoryPrototype>(vm.heap)) WebAssemblyMemoryPrototype(vm, structure);
100
    auto* object = new (NotNull, allocateCell<WebAssemblyMemoryPrototype>(vm.heap)) WebAssemblyMemoryPrototype(vm, structure);
101
    object->finishCreation(vm, globalObject);
101
    object->finishCreation(vm);
102
    return object;
102
    return object;
103
}
103
}
104
104
Lines 107-116 Structure* WebAssemblyMemoryPrototype::createStructure(VM& vm, JSGlobalObject* g a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp_sec6
107
    return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
107
    return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
108
}
108
}
109
109
110
void WebAssemblyMemoryPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
110
void WebAssemblyMemoryPrototype::finishCreation(VM& vm)
111
{
111
{
112
    Base::finishCreation(vm);
112
    Base::finishCreation(vm);
113
    JSC_NATIVE_GETTER("buffer", webAssemblyMemoryProtoFuncBuffer, DontEnum | Accessor);
113
    ASSERT(inherits(vm, info()));
114
}
114
}
115
115
116
WebAssemblyMemoryPrototype::WebAssemblyMemoryPrototype(VM& vm, Structure* structure)
116
WebAssemblyMemoryPrototype::WebAssemblyMemoryPrototype(VM& vm, Structure* structure)
- a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h -2 / +2 lines
Lines 1-5 a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h_sec1
1
/*
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
2
 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 43-49 public: a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h_sec2
43
    DECLARE_INFO;
43
    DECLARE_INFO;
44
44
45
protected:
45
protected:
46
    void finishCreation(VM&, JSGlobalObject*);
46
    void finishCreation(VM&);
47
47
48
private:
48
private:
49
    WebAssemblyMemoryPrototype(VM&, Structure*);
49
    WebAssemblyMemoryPrototype(VM&, Structure*);
- a/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp -18 / +106 lines
Lines 1-5 a/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp_sec1
1
/*
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
2
 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 28-52 a/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp_sec2
28
28
29
#if ENABLE(WEBASSEMBLY)
29
#if ENABLE(WEBASSEMBLY)
30
30
31
#include "Exception.h"
31
#include "FunctionPrototype.h"
32
#include "FunctionPrototype.h"
32
#include "JSCInlines.h"
33
#include "JSCInlines.h"
34
#include "JSPromiseDeferred.h"
35
#include "JSWebAssemblyHelpers.h"
36
#include "JSWebAssemblyInstance.h"
37
#include "JSWebAssemblyModule.h"
38
#include "ObjectConstructor.h"
39
#include "WasmPlan.h"
40
#include "WebAssemblyInstanceConstructor.h"
41
#include "WebAssemblyModuleConstructor.h"
33
42
34
namespace JSC {
43
namespace JSC {
35
44
static EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState*);
36
static EncodedJSValue JSC_HOST_CALL webAssemblyFunctionValidate(ExecState* exec)
45
static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState*);
37
{
46
static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState*);
38
    VM& vm = exec->vm();
39
    auto scope = DECLARE_THROW_SCOPE(vm);
40
    return JSValue::encode(throwException(exec, scope, createError(exec, ASCIILiteral("WebAssembly doesn't yet implement the validate function property"))));
41
}
42
43
static EncodedJSValue JSC_HOST_CALL webAssemblyFunctionCompile(ExecState* exec)
44
{
45
    VM& vm = exec->vm();
46
    auto scope = DECLARE_THROW_SCOPE(vm);
47
    return JSValue::encode(throwException(exec, scope, createError(exec, ASCIILiteral("WebAssembly doesn't yet implement the compile function property"))));
48
}
49
50
}
47
}
51
48
52
#include "WebAssemblyPrototype.lut.h"
49
#include "WebAssemblyPrototype.lut.h"
Lines 57-67 const ClassInfo WebAssemblyPrototype::s_info = { "WebAssembly.prototype", &Base: a/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp_sec3
57
54
58
/* Source for WebAssemblyPrototype.lut.h
55
/* Source for WebAssemblyPrototype.lut.h
59
 @begin prototypeTableWebAssembly
56
 @begin prototypeTableWebAssembly
60
 validate webAssemblyFunctionValidate  DontEnum|Function 1
57
 validate    webAssemblyValidateFunc    DontEnum|Function 1
61
 compile  webAssemblyFunctionCompile   DontEnum|Function 1
58
 compile     webAssemblyCompileFunc     DontEnum|Function 1
59
 instantiate webAssemblyInstantiateFunc DontEnum|Function 1
62
 @end
60
 @end
63
 */
61
 */
64
62
63
EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState* exec)
64
{
65
    VM& vm = exec->vm();
66
    auto scope = DECLARE_THROW_SCOPE(vm);
67
68
    size_t byteOffset;
69
    size_t byteSize;
70
    uint8_t* base = getWasmBufferFromValue(exec, exec->argument(0), byteOffset, byteSize);
71
    RETURN_IF_EXCEPTION(scope, encodedJSValue());
72
    Wasm::Plan plan(&vm, base + byteOffset, byteSize);
73
    // FIXME: We might want to throw an OOM exception here if we detect that something will OOM.
74
    // https://bugs.webkit.org/show_bug.cgi?id=166015
75
    return JSValue::encode(jsBoolean(plan.parseAndValidateModule()));
76
}
77
78
EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState* exec)
79
{
80
    VM& vm = exec->vm();
81
    auto catchScope = DECLARE_CATCH_SCOPE(vm);
82
83
    JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, exec->lexicalGlobalObject());
84
    RETURN_IF_EXCEPTION(catchScope, encodedJSValue());
85
86
    // FIXME: Make this truly asynchronous:
87
    // https://bugs.webkit.org/show_bug.cgi?id=166016
88
    JSValue module = WebAssemblyModuleConstructor::createModule(exec, exec->argument(0), exec->lexicalGlobalObject()->WebAssemblyModuleStructure());
89
    if (Exception* exception = catchScope.exception()) {
90
        catchScope.clearException();
91
        promise->reject(exec, exception->value());
92
        return JSValue::encode(promise->promise());
93
    }
94
95
    promise->resolve(exec, module);
96
    return JSValue::encode(promise->promise());
97
}
98
99
EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState* exec)
100
{
101
    VM& vm = exec->vm();
102
    auto catchScope = DECLARE_CATCH_SCOPE(vm);
103
104
    // FIXME: Make this API truly asynchronous: https://bugs.webkit.org/show_bug.cgi?id=169187
105
106
    JSPromiseDeferred* promise = JSPromiseDeferred::create(exec, exec->lexicalGlobalObject());
107
    RETURN_IF_EXCEPTION(catchScope, encodedJSValue());
108
109
    auto reject = [&] () {
110
        Exception* exception = catchScope.exception();
111
        ASSERT(exception);
112
        catchScope.clearException();
113
        promise->reject(exec, exception->value());
114
        return JSValue::encode(promise->promise());
115
    };
116
117
    JSValue importArgument = exec->argument(1);
118
    JSObject* importObject = importArgument.getObject();
119
    if (!importArgument.isUndefined() && !importObject) {
120
        promise->reject(exec, createTypeError(exec,
121
            ASCIILiteral("second argument to WebAssembly.instantiate must be undefined or an Object"), defaultSourceAppender, runtimeTypeForValue(importArgument)));
122
        return JSValue::encode(promise->promise());
123
    }
124
125
    JSValue firstArgument = exec->argument(0);
126
    JSValue module;
127
    bool firstArgumentIsModule = false;
128
    if (firstArgument.inherits(vm, JSWebAssemblyModule::info())) {
129
        firstArgumentIsModule = true;
130
        module = firstArgument;
131
    } else {
132
        module = WebAssemblyModuleConstructor::createModule(exec, firstArgument, exec->lexicalGlobalObject()->WebAssemblyModuleStructure());
133
        if (catchScope.exception())
134
            return reject();
135
    }
136
137
    JSWebAssemblyInstance* instance = WebAssemblyInstanceConstructor::createInstance(exec, jsCast<JSWebAssemblyModule*>(module), importObject, exec->lexicalGlobalObject()->WebAssemblyInstanceStructure());
138
    if (catchScope.exception())
139
        return reject();
140
141
    if (firstArgumentIsModule)
142
        promise->resolve(exec, instance);
143
    else {
144
        JSObject* result = constructEmptyObject(exec);
145
        result->putDirect(vm, Identifier::fromString(&vm, ASCIILiteral("module")), module);
146
        result->putDirect(vm, Identifier::fromString(&vm, ASCIILiteral("instance")), instance);
147
        promise->resolve(exec, result);
148
    }
149
150
    return JSValue::encode(promise->promise());
151
}
152
65
WebAssemblyPrototype* WebAssemblyPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
153
WebAssemblyPrototype* WebAssemblyPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
66
{
154
{
67
    auto* object = new (NotNull, allocateCell<WebAssemblyPrototype>(vm.heap)) WebAssemblyPrototype(vm, structure);
155
    auto* object = new (NotNull, allocateCell<WebAssemblyPrototype>(vm.heap)) WebAssemblyPrototype(vm, structure);
- a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp -34 / +24 lines
Lines 1-5 a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp_sec1
1
/*
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
2
 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 33-38 a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp_sec2
33
#include "JSWebAssemblyHelpers.h"
33
#include "JSWebAssemblyHelpers.h"
34
#include "JSWebAssemblyTable.h"
34
#include "JSWebAssemblyTable.h"
35
35
36
namespace JSC {
37
static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState*);
38
static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState*);
39
static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState*);
40
static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState*);
41
}
42
36
#include "WebAssemblyTablePrototype.lut.h"
43
#include "WebAssemblyTablePrototype.lut.h"
37
44
38
namespace JSC {
45
namespace JSC {
Lines 41-46 const ClassInfo WebAssemblyTablePrototype::s_info = { "WebAssembly.Table.prototy a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp_sec3
41
48
42
/* Source for WebAssemblyTablePrototype.lut.h
49
/* Source for WebAssemblyTablePrototype.lut.h
43
 @begin prototypeTableWebAssemblyTable
50
 @begin prototypeTableWebAssemblyTable
51
 length webAssemblyTableProtoFuncLength DontEnum|Accessor 0
52
 grow   webAssemblyTableProtoFuncGrow   DontEnum|Function 1
53
 get    webAssemblyTableProtoFuncGet    DontEnum|Function 1
54
 set    webAssemblyTableProtoFuncSet    DontEnum|Function 2
44
 @end
55
 @end
45
 */
56
 */
46
57
Lines 56-66 static ALWAYS_INLINE JSWebAssemblyTable* getTable(ExecState* exec, VM& vm, JSVal a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp_sec4
56
    return result;
67
    return result;
57
}
68
}
58
69
59
EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState*);
60
EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState*);
61
EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState*);
62
EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState*);
63
64
EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState* exec)
70
EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState* exec)
65
{
71
{
66
    VM& vm = exec->vm();
72
    VM& vm = exec->vm();
Lines 81-91 EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState* exec) a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp_sec5
81
87
82
    uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
88
    uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
83
    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
89
    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
84
    if (!table->grow(index)) {
90
    if (!table->grow(index))
85
        throwException(exec, throwScope,
91
        return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.grow could not grow the table"))));
86
            createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.grow could not grow the table")));
87
        return { };
88
    }
89
92
90
    return JSValue::encode(jsUndefined());
93
    return JSValue::encode(jsUndefined());
91
}
94
}
Lines 100-110 EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState* exec) a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp_sec6
100
103
101
    uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
104
    uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
102
    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
105
    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
103
    if (index >= table->size()) {
106
    if (index >= table->size())
104
        throwException(exec, throwScope,
107
        return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.get expects an integer less than the size of the table"))));
105
            createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.get expects an integer less than the size of the table")));
106
        return { };
107
    }
108
108
109
    if (JSObject* result = table->getFunction(index))
109
    if (JSObject* result = table->getFunction(index))
110
        return JSValue::encode(result);
110
        return JSValue::encode(result);
Lines 122-141 EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec) a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp_sec7
122
    JSValue value = exec->argument(1);
122
    JSValue value = exec->argument(1);
123
    WebAssemblyFunction* wasmFunction;
123
    WebAssemblyFunction* wasmFunction;
124
    WebAssemblyWrapperFunction* wasmWrapperFunction;
124
    WebAssemblyWrapperFunction* wasmWrapperFunction;
125
    if (!value.isNull() && !isWebAssemblyHostFunction(vm, value, wasmFunction, wasmWrapperFunction)) {
125
    if (!value.isNull() && !isWebAssemblyHostFunction(vm, value, wasmFunction, wasmWrapperFunction))
126
        throwException(exec, throwScope,
126
        return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects the second argument to be null or an instance of WebAssembly.Function"))));
127
            createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects the second argument to be null or an instance of WebAssembly.Function")));
128
        return { };
129
    }
130
127
131
    uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
128
    uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
132
    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
129
    RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
133
130
134
    if (index >= table->size()) {
131
    if (index >= table->size())
135
        throwException(exec, throwScope,
132
        return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects an integer less than the size of the table"))));
136
            createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects an integer less than the size of the table")));
137
        return { };
138
    }
139
133
140
    if (value.isNull())
134
    if (value.isNull())
141
        table->clearFunction(index);
135
        table->clearFunction(index);
Lines 151-160 EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec) a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp_sec8
151
    return JSValue::encode(jsUndefined());
145
    return JSValue::encode(jsUndefined());
152
}
146
}
153
147
154
WebAssemblyTablePrototype* WebAssemblyTablePrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
148
WebAssemblyTablePrototype* WebAssemblyTablePrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
155
{
149
{
156
    auto* object = new (NotNull, allocateCell<WebAssemblyTablePrototype>(vm.heap)) WebAssemblyTablePrototype(vm, structure);
150
    auto* object = new (NotNull, allocateCell<WebAssemblyTablePrototype>(vm.heap)) WebAssemblyTablePrototype(vm, structure);
157
    object->finishCreation(vm, globalObject);
151
    object->finishCreation(vm);
158
    return object;
152
    return object;
159
}
153
}
160
154
Lines 163-176 Structure* WebAssemblyTablePrototype::createStructure(VM& vm, JSGlobalObject* gl a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp_sec9
163
    return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
157
    return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
164
}
158
}
165
159
166
void WebAssemblyTablePrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
160
void WebAssemblyTablePrototype::finishCreation(VM& vm)
167
{
161
{
168
    Base::finishCreation(vm);
162
    Base::finishCreation(vm);
169
163
    ASSERT(inherits(vm, info()));
170
    JSC_NATIVE_GETTER("length", webAssemblyTableProtoFuncLength, DontEnum | Accessor);
171
    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("grow", webAssemblyTableProtoFuncGrow, DontEnum, 1);
172
    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("get", webAssemblyTableProtoFuncGet, DontEnum, 1);
173
    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("set", webAssemblyTableProtoFuncSet, DontEnum, 2);
174
}
164
}
175
165
176
WebAssemblyTablePrototype::WebAssemblyTablePrototype(VM& vm, Structure* structure)
166
WebAssemblyTablePrototype::WebAssemblyTablePrototype(VM& vm, Structure* structure)
- a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h -3 / +2 lines
Lines 1-5 a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h_sec1
1
/*
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
2
 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3
 *
3
 *
4
 * Redistribution and use in source and binary forms, with or without
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
5
 * modification, are permitted provided that the following conditions
Lines 43-49 public: a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h_sec2
43
    DECLARE_INFO;
43
    DECLARE_INFO;
44
44
45
protected:
45
protected:
46
    void finishCreation(VM&, JSGlobalObject*);
46
    void finishCreation(VM&);
47
47
48
private:
48
private:
49
    WebAssemblyTablePrototype(VM&, Structure*);
49
    WebAssemblyTablePrototype(VM&, Structure*);
50
- 

Return to Bug 170187