COMMIT_MESSAGE

 1wasm-misc
 2

Source/JavaScriptCore/ChangeLog

 12017-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
1362017-03-27 JF Bastien <jfbastien@apple.com>
237
338 WebAssembly: JSWebAssemblyCodeBlock.h belongs in JavaScriptCore/wasm/js not JavaScriptCore/wasm

Source/JavaScriptCore/wasm/JSWebAssembly.cpp

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
55 * modification, are permitted provided that the following conditions

2828
2929#if ENABLE(WEBASSEMBLY)
3030
31 #include "Exception.h"
32 #include "FunctionPrototype.h"
3331#include "JSCInlines.h"
34 #include "JSPromiseDeferred.h"
35 #include "JSWebAssemblyHelpers.h"
36 #include "ObjectConstructor.h"
37 #include "WasmPlan.h"
38 #include "WebAssemblyModuleConstructor.h"
3932
4033namespace JSC {
4134
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 
13835const ClassInfo JSWebAssembly::s_info = { "WebAssembly", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssembly) };
13936
140 JSWebAssembly* JSWebAssembly::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
 37STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSWebAssembly);
 38
 39JSWebAssembly* JSWebAssembly::create(VM& vm, JSGlobalObject*, Structure* structure)
14140{
14241 auto* object = new (NotNull, allocateCell<JSWebAssembly>(vm.heap)) JSWebAssembly(vm, structure);
143  object->finishCreation(vm, globalObject);
 42 object->finishCreation(vm);
14443 return object;
14544}
14645

@@Structure* JSWebAssembly::createStructure(VM& vm, JSGlobalObject* globalObject,
14948 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
15049}
15150
152 void JSWebAssembly::finishCreation(VM& vm, JSGlobalObject* globalObject)
 51void JSWebAssembly::finishCreation(VM& vm)
15352{
15453 Base::finishCreation(vm);
15554 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);
15955}
16056
16157JSWebAssembly::JSWebAssembly(VM& vm, Structure* structure)

Source/JavaScriptCore/wasm/JSWebAssembly.h

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
55 * modification, are permitted provided that the following conditions

@@public:
6767 DECLARE_INFO;
6868
6969protected:
70  void finishCreation(VM&, JSGlobalObject*);
 70 void finishCreation(VM&);
7171
7272private:
7373 JSWebAssembly(VM&, Structure*);

Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp

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
55 * modification, are permitted provided that the following conditions

3636
3737namespace JSC {
3838static EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState*);
 39static EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState*);
3940}
4041
4142#include "WebAssemblyMemoryPrototype.lut.h"

@@const ClassInfo WebAssemblyMemoryPrototype::s_info = { "WebAssembly.Memory.proto
4748
4849/* Source for WebAssemblyMemoryPrototype.lut.h
4950@begin prototypeTableWebAssemblyMemory
50  grow webAssemblyMemoryProtoFuncGrow DontEnum|Function 1
 51 grow webAssemblyMemoryProtoFuncGrow DontEnum|Function 1
 52 buffer webAssemblyMemoryProtoFuncBuffer DontEnum|Accessor 0
5153@end
5254*/
5355
54 EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState*);
55 
5656ALWAYS_INLINE JSWebAssemblyMemory* getMemory(ExecState* exec, JSValue value)
5757{
5858 VM& vm = exec->vm();

@@ALWAYS_INLINE JSWebAssemblyMemory* getMemory(ExecState* exec, JSValue value)
6767 return memory;
6868}
6969
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 
8070EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState* exec)
8171{
8272 VM& vm = exec->vm();

@@EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState* exec)
9585 return JSValue::encode(jsNumber(result.pageCount()));
9686}
9787
98 WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
 88EncodedJSValue 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
 98WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
9999{
100100 auto* object = new (NotNull, allocateCell<WebAssemblyMemoryPrototype>(vm.heap)) WebAssemblyMemoryPrototype(vm, structure);
101  object->finishCreation(vm, globalObject);
 101 object->finishCreation(vm);
102102 return object;
103103}
104104

@@Structure* WebAssemblyMemoryPrototype::createStructure(VM& vm, JSGlobalObject* g
107107 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
108108}
109109
110 void WebAssemblyMemoryPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
 110void WebAssemblyMemoryPrototype::finishCreation(VM& vm)
111111{
112112 Base::finishCreation(vm);
113  JSC_NATIVE_GETTER("buffer", webAssemblyMemoryProtoFuncBuffer, DontEnum | Accessor);
 113 ASSERT(inherits(vm, info()));
114114}
115115
116116WebAssemblyMemoryPrototype::WebAssemblyMemoryPrototype(VM& vm, Structure* structure)

Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h

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
55 * modification, are permitted provided that the following conditions

@@public:
4343 DECLARE_INFO;
4444
4545protected:
46  void finishCreation(VM&, JSGlobalObject*);
 46 void finishCreation(VM&);
4747
4848private:
4949 WebAssemblyMemoryPrototype(VM&, Structure*);

Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp

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
55 * modification, are permitted provided that the following conditions

2828
2929#if ENABLE(WEBASSEMBLY)
3030
 31#include "Exception.h"
3132#include "FunctionPrototype.h"
3233#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"
3342
3443namespace JSC {
35 
36 static EncodedJSValue JSC_HOST_CALL webAssemblyFunctionValidate(ExecState* exec)
37 {
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 
 44static EncodedJSValue JSC_HOST_CALL webAssemblyValidateFunc(ExecState*);
 45static EncodedJSValue JSC_HOST_CALL webAssemblyCompileFunc(ExecState*);
 46static EncodedJSValue JSC_HOST_CALL webAssemblyInstantiateFunc(ExecState*);
5047}
5148
5249#include "WebAssemblyPrototype.lut.h"

@@const ClassInfo WebAssemblyPrototype::s_info = { "WebAssembly.prototype", &Base:
5754
5855/* Source for WebAssemblyPrototype.lut.h
5956 @begin prototypeTableWebAssembly
60  validate webAssemblyFunctionValidate DontEnum|Function 1
61  compile webAssemblyFunctionCompile DontEnum|Function 1
 57 validate webAssemblyValidateFunc DontEnum|Function 1
 58 compile webAssemblyCompileFunc DontEnum|Function 1
 59 instantiate webAssemblyInstantiateFunc DontEnum|Function 1
6260 @end
6361 */
6462
 63EncodedJSValue 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
 78EncodedJSValue 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
 99EncodedJSValue 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
65153WebAssemblyPrototype* WebAssemblyPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
66154{
67155 auto* object = new (NotNull, allocateCell<WebAssemblyPrototype>(vm.heap)) WebAssemblyPrototype(vm, structure);

Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp

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
55 * modification, are permitted provided that the following conditions

3333#include "JSWebAssemblyHelpers.h"
3434#include "JSWebAssemblyTable.h"
3535
 36namespace JSC {
 37static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState*);
 38static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState*);
 39static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState*);
 40static EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState*);
 41}
 42
3643#include "WebAssemblyTablePrototype.lut.h"
3744
3845namespace JSC {

@@const ClassInfo WebAssemblyTablePrototype::s_info = { "WebAssembly.Table.prototy
4148
4249/* Source for WebAssemblyTablePrototype.lut.h
4350 @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
4455 @end
4556 */
4657

@@static ALWAYS_INLINE JSWebAssemblyTable* getTable(ExecState* exec, VM& vm, JSVal
5667 return result;
5768}
5869
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 
6470EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState* exec)
6571{
6672 VM& vm = exec->vm();

@@EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState* exec)
8187
8288 uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
8389 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
84  if (!table->grow(index)) {
85  throwException(exec, throwScope,
86  createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.grow could not grow the table")));
87  return { };
88  }
 90 if (!table->grow(index))
 91 return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.grow could not grow the table"))));
8992
9093 return JSValue::encode(jsUndefined());
9194}

@@EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState* exec)
100103
101104 uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
102105 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
103  if (index >= table->size()) {
104  throwException(exec, throwScope,
105  createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.get expects an integer less than the size of the table")));
106  return { };
107  }
 106 if (index >= table->size())
 107 return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.get expects an integer less than the size of the table"))));
108108
109109 if (JSObject* result = table->getFunction(index))
110110 return JSValue::encode(result);

@@EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec)
122122 JSValue value = exec->argument(1);
123123 WebAssemblyFunction* wasmFunction;
124124 WebAssemblyWrapperFunction* wasmWrapperFunction;
125  if (!value.isNull() && !isWebAssemblyHostFunction(vm, value, wasmFunction, wasmWrapperFunction)) {
126  throwException(exec, throwScope,
127  createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects the second argument to be null or an instance of WebAssembly.Function")));
128  return { };
129  }
 125 if (!value.isNull() && !isWebAssemblyHostFunction(vm, value, wasmFunction, wasmWrapperFunction))
 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"))));
130127
131128 uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
132129 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
133130
134  if (index >= table->size()) {
135  throwException(exec, throwScope,
136  createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects an integer less than the size of the table")));
137  return { };
138  }
 131 if (index >= table->size())
 132 return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects an integer less than the size of the table"))));
139133
140134 if (value.isNull())
141135 table->clearFunction(index);

@@EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec)
151145 return JSValue::encode(jsUndefined());
152146}
153147
154 WebAssemblyTablePrototype* WebAssemblyTablePrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
 148WebAssemblyTablePrototype* WebAssemblyTablePrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
155149{
156150 auto* object = new (NotNull, allocateCell<WebAssemblyTablePrototype>(vm.heap)) WebAssemblyTablePrototype(vm, structure);
157  object->finishCreation(vm, globalObject);
 151 object->finishCreation(vm);
158152 return object;
159153}
160154

@@Structure* WebAssemblyTablePrototype::createStructure(VM& vm, JSGlobalObject* gl
163157 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
164158}
165159
166 void WebAssemblyTablePrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
 160void WebAssemblyTablePrototype::finishCreation(VM& vm)
167161{
168162 Base::finishCreation(vm);
169 
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);
 163 ASSERT(inherits(vm, info()));
174164}
175165
176166WebAssemblyTablePrototype::WebAssemblyTablePrototype(VM& vm, Structure* structure)

Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h

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
55 * modification, are permitted provided that the following conditions

@@public:
4343 DECLARE_INFO;
4444
4545protected:
46  void finishCreation(VM&, JSGlobalObject*);
 46 void finishCreation(VM&);
4747
4848private:
4949 WebAssemblyTablePrototype(VM&, Structure*);