summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/wasm/js
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/wasm/js')
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyCallee.cpp56
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyCallee.h71
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyCompileError.cpp61
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyCompileError.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h76
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp99
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h117
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.cpp61
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp148
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h69
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp98
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h123
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp54
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.h52
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp136
-rw-r--r--Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h84
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.cpp102
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.h58
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorPrototype.cpp69
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorPrototype.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp187
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyFunction.h80
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyFunctionCell.cpp0
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyFunctionCell.h0
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp345
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.h59
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.cpp69
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.cpp102
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.h58
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.cpp69
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp160
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.h59
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp123
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp156
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.h61
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.cpp112
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp291
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h67
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp89
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp102
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.h58
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorPrototype.cpp69
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorPrototype.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.cpp150
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.h59
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp178
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h54
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyToJSCallee.cpp67
-rw-r--r--Source/JavaScriptCore/wasm/js/WebAssemblyToJSCallee.h53
55 files changed, 4897 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCallee.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblyCallee.cpp
new file mode 100644
index 000000000..c27712a10
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyCallee.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSWebAssemblyCallee.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCInlines.h"
+
+namespace JSC {
+
+const ClassInfo JSWebAssemblyCallee::s_info = { "WebAssemblyCallee", nullptr, 0, CREATE_METHOD_TABLE(JSWebAssemblyCallee) };
+
+JSWebAssemblyCallee::JSWebAssemblyCallee(VM& vm)
+ : Base(vm, vm.webAssemblyCalleeStructure.get())
+{ }
+
+void JSWebAssemblyCallee::finishCreation(VM& vm, Wasm::Entrypoint&& entrypoint)
+{
+ Base::finishCreation(vm);
+
+ m_entrypoint = WTFMove(entrypoint);
+}
+
+void JSWebAssemblyCallee::destroy(JSCell* cell)
+{
+ JSWebAssemblyCallee* thisObject = static_cast<JSWebAssemblyCallee*>(cell);
+ thisObject->JSWebAssemblyCallee::~JSWebAssemblyCallee();
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCallee.h b/Source/JavaScriptCore/wasm/js/JSWebAssemblyCallee.h
new file mode 100644
index 000000000..b8777da0d
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyCallee.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCell.h"
+#include "RegisterAtOffsetList.h"
+#include "Structure.h"
+#include "WasmFormat.h"
+
+namespace JSC {
+
+class JSWebAssemblyCallee : public JSCell {
+public:
+ typedef JSCell Base;
+ static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
+
+ static JSWebAssemblyCallee* create(VM& vm, Wasm::Entrypoint&& entrypoint)
+ {
+ JSWebAssemblyCallee* callee = new (NotNull, allocateCell<JSWebAssemblyCallee>(vm.heap)) JSWebAssemblyCallee(vm);
+ callee->finishCreation(vm, WTFMove(entrypoint));
+ return callee;
+ }
+
+ static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+ {
+ return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
+ }
+
+ DECLARE_EXPORT_INFO;
+ static const bool needsDestruction = true;
+ static void destroy(JSCell*);
+
+ void* entrypoint() { return m_entrypoint.compilation->code().executableAddress(); }
+
+ RegisterAtOffsetList* calleeSaveRegisters() { return &m_entrypoint.calleeSaveRegisters; }
+
+private:
+ void finishCreation(VM&, Wasm::Entrypoint&&);
+ JSWebAssemblyCallee(VM&);
+
+ Wasm::Entrypoint m_entrypoint;
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCompileError.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblyCompileError.cpp
new file mode 100644
index 000000000..e485889d1
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyCompileError.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSWebAssemblyCompileError.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCInlines.h"
+
+namespace JSC {
+
+JSWebAssemblyCompileError* JSWebAssemblyCompileError::create(ExecState* state, VM& vm, Structure* structure, const String& message)
+{
+ auto* instance = new (NotNull, allocateCell<JSWebAssemblyCompileError>(vm.heap)) JSWebAssemblyCompileError(vm, structure);
+ instance->m_sourceAppender = defaultSourceAppender;
+ bool useCurrentFrame = true;
+ instance->finishCreation(state, vm, message, useCurrentFrame);
+ return instance;
+}
+
+JSWebAssemblyCompileError::JSWebAssemblyCompileError(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+const ClassInfo JSWebAssemblyCompileError::s_info = { "WebAssembly.CompileError", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssemblyCompileError) };
+
+
+JSObject* createJSWebAssemblyCompileError(ExecState* state, VM& vm, const String& message)
+{
+ ASSERT(!message.isEmpty());
+ JSGlobalObject* globalObject = state->lexicalGlobalObject();
+ return JSWebAssemblyCompileError::create(state, vm, globalObject->WebAssemblyCompileErrorStructure(), message);
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyCompileError.h b/Source/JavaScriptCore/wasm/js/JSWebAssemblyCompileError.h
new file mode 100644
index 000000000..04e3f2af4
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyCompileError.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "ErrorInstance.h"
+
+namespace JSC {
+
+class JSWebAssemblyCompileError : public ErrorInstance {
+public:
+ typedef ErrorInstance Base;
+
+ static JSWebAssemblyCompileError* create(ExecState*, VM&, Structure*, const String&);
+ static JSWebAssemblyCompileError* create(ExecState* state, VM& vm, Structure* structure, JSValue message)
+ {
+ return create(state, vm, structure, message.isUndefined() ? String() : message.toWTFString(state));
+ }
+
+ DECLARE_INFO;
+
+protected:
+ JSWebAssemblyCompileError(VM&, Structure*);
+};
+
+JSObject* createJSWebAssemblyCompileError(ExecState*, VM&, const String&);
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h b/Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h
new file mode 100644
index 000000000..b645a5635
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyHelpers.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSArrayBuffer.h"
+#include "JSCJSValue.h"
+
+namespace JSC {
+
+ALWAYS_INLINE uint32_t toNonWrappingUint32(ExecState* exec, JSValue value)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ double doubleValue = value.toInteger(exec);
+ RETURN_IF_EXCEPTION(throwScope, { });
+ if (doubleValue < 0 || doubleValue > UINT_MAX) {
+ throwException(exec, throwScope,
+ createRangeError(exec, ASCIILiteral("Expect an integer argument in the range: [0, 2^32 - 1]")));
+ return { };
+ }
+
+ return static_cast<uint32_t>(doubleValue);
+}
+
+ALWAYS_INLINE uint8_t* getWasmBufferFromValue(ExecState* exec, JSValue value, size_t& byteOffset, size_t& byteSize)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ // If the given bytes argument is not a BufferSource, a TypeError exception is thrown.
+ JSArrayBuffer* arrayBuffer = value.getObject() ? jsDynamicCast<JSArrayBuffer*>(vm, value.getObject()) : nullptr;
+ JSArrayBufferView* arrayBufferView = value.getObject() ? jsDynamicCast<JSArrayBufferView*>(vm, value.getObject()) : nullptr;
+ if (!(arrayBuffer || arrayBufferView)) {
+ throwException(exec, throwScope, createTypeError(exec,
+ ASCIILiteral("first argument must be an ArrayBufferView or an ArrayBuffer"), defaultSourceAppender, runtimeTypeForValue(value)));
+ return nullptr;
+ }
+
+ if (arrayBufferView ? arrayBufferView->isNeutered() : arrayBuffer->impl()->isNeutered()) {
+ throwException(exec, throwScope, createTypeError(exec,
+ ASCIILiteral("underlying TypedArray has been detatched from the ArrayBuffer"), defaultSourceAppender, runtimeTypeForValue(value)));
+ return nullptr;
+ }
+
+ byteOffset = arrayBufferView ? arrayBufferView->byteOffset() : 0;
+ byteSize = arrayBufferView ? arrayBufferView->length() : arrayBuffer->impl()->byteLength();
+ return arrayBufferView ? static_cast<uint8_t*>(arrayBufferView->vector()) : static_cast<uint8_t*>(arrayBuffer->impl()->data());
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp
new file mode 100644
index 000000000..fbc1cebfb
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSWebAssemblyInstance.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "AbstractModuleRecord.h"
+#include "JSCInlines.h"
+#include "JSModuleEnvironment.h"
+#include "JSModuleNamespaceObject.h"
+#include "JSWebAssemblyMemory.h"
+#include "JSWebAssemblyModule.h"
+#include <wtf/StdLibExtras.h>
+
+namespace JSC {
+
+JSWebAssemblyInstance* JSWebAssemblyInstance::create(VM& vm, Structure* structure, JSWebAssemblyModule* module, JSModuleNamespaceObject* moduleNamespaceObject)
+{
+ // FIXME: These objects could be pretty big we should try to throw OOM here.
+ auto* instance = new (NotNull, allocateCell<JSWebAssemblyInstance>(vm.heap, allocationSize(module->moduleInformation().importFunctionSignatureIndices.size()))) JSWebAssemblyInstance(vm, structure, module->moduleInformation().importFunctionSignatureIndices.size());
+ instance->finishCreation(vm, module, moduleNamespaceObject);
+ return instance;
+}
+
+Structure* JSWebAssemblyInstance::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSWebAssemblyInstance::JSWebAssemblyInstance(VM& vm, Structure* structure, unsigned numImportFunctions)
+ : Base(vm, structure)
+ , m_numImportFunctions(numImportFunctions)
+{
+ memset(importFunctions(), 0, m_numImportFunctions * sizeof(WriteBarrier<JSCell>));
+}
+
+void JSWebAssemblyInstance::finishCreation(VM& vm, JSWebAssemblyModule* module, JSModuleNamespaceObject* moduleNamespaceObject)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(vm, info()));
+
+ const size_t extraMemorySize = module->moduleInformation().globals.size() * sizeof(Register);
+ m_globals = MallocPtr<uint64_t>::malloc(extraMemorySize);
+ heap()->reportExtraMemoryAllocated(extraMemorySize);
+
+ m_module.set(vm, this, module);
+ m_moduleNamespaceObject.set(vm, this, moduleNamespaceObject);
+ putDirect(vm, Identifier::fromString(&vm, "exports"), moduleNamespaceObject, None);
+}
+
+void JSWebAssemblyInstance::destroy(JSCell* cell)
+{
+ static_cast<JSWebAssemblyInstance*>(cell)->JSWebAssemblyInstance::~JSWebAssemblyInstance();
+}
+
+void JSWebAssemblyInstance::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ auto* thisObject = jsCast<JSWebAssemblyInstance*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_module);
+ visitor.append(thisObject->m_moduleNamespaceObject);
+ visitor.append(thisObject->m_memory);
+ visitor.append(thisObject->m_table);
+ visitor.reportExtraMemoryVisited(thisObject->module()->moduleInformation().globals.size());
+ for (unsigned i = 0; i < thisObject->m_numImportFunctions; ++i)
+ visitor.append(*thisObject->importFunction(i));
+}
+
+const ClassInfo JSWebAssemblyInstance::s_info = { "WebAssembly.Instance", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssemblyInstance) };
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h b/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h
new file mode 100644
index 000000000..99a2c90f7
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyInstance.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+#include "JSWebAssemblyMemory.h"
+#include "JSWebAssemblyTable.h"
+
+namespace JSC {
+
+class JSModuleNamespaceObject;
+class JSWebAssemblyModule;
+
+class JSWebAssemblyInstance : public JSDestructibleObject {
+public:
+ typedef JSDestructibleObject Base;
+
+
+ static JSWebAssemblyInstance* create(VM&, Structure*, JSWebAssemblyModule*, JSModuleNamespaceObject*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+ JSWebAssemblyModule* module()
+ {
+ ASSERT(m_module);
+ return m_module.get();
+ }
+
+ WriteBarrier<JSCell>* importFunction(unsigned idx)
+ {
+ RELEASE_ASSERT(idx < m_numImportFunctions);
+ return &importFunctions()[idx];
+ }
+
+ WriteBarrier<JSCell>* importFunctions()
+ {
+ return bitwise_cast<WriteBarrier<JSCell>*>(bitwise_cast<char*>(this) + offsetOfImportFunctions());
+ }
+
+ void setImportFunction(VM& vm, JSCell* value, unsigned idx)
+ {
+ importFunction(idx)->set(vm, this, value);
+ }
+
+ JSWebAssemblyMemory* memory() { return m_memory.get(); }
+ void setMemory(VM& vm, JSWebAssemblyMemory* memory) { m_memory.set(vm, this, memory); }
+
+ JSWebAssemblyTable* table() { return m_table.get(); }
+ void setTable(VM& vm, JSWebAssemblyTable* table) { m_table.set(vm, this, table); }
+
+ int32_t loadI32Global(unsigned i) const { return m_globals.get()[i]; }
+ int64_t loadI64Global(unsigned i) const { return m_globals.get()[i]; }
+ float loadF32Global(unsigned i) const { return bitwise_cast<float>(loadI32Global(i)); }
+ double loadF64Global(unsigned i) const { return bitwise_cast<double>(loadI64Global(i)); }
+ void setGlobal(unsigned i, int64_t bits) { m_globals.get()[i] = bits; }
+
+ static size_t offsetOfImportFunction(unsigned idx)
+ {
+ return offsetOfImportFunctions() + sizeof(WriteBarrier<JSCell>) * idx;
+ }
+
+ static ptrdiff_t offsetOfMemory() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_memory); }
+ static ptrdiff_t offsetOfTable() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_table); }
+ static ptrdiff_t offsetOfGlobals() { return OBJECT_OFFSETOF(JSWebAssemblyInstance, m_globals); }
+ static size_t offsetOfImportFunctions() { return WTF::roundUpToMultipleOf<sizeof(WriteBarrier<JSCell>)>(sizeof(JSWebAssemblyInstance)); }
+ static size_t offsetOfImportFunction(size_t importFunctionNum) { return offsetOfImportFunctions() + importFunctionNum * sizeof(sizeof(WriteBarrier<JSCell>)); }
+
+protected:
+ JSWebAssemblyInstance(VM&, Structure*, unsigned numImportFunctions);
+ void finishCreation(VM&, JSWebAssemblyModule*, JSModuleNamespaceObject*);
+ static void destroy(JSCell*);
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+ static size_t allocationSize(unsigned numImportFunctions)
+ {
+ return offsetOfImportFunctions() + sizeof(WriteBarrier<JSCell>) * numImportFunctions;
+ }
+
+private:
+ WriteBarrier<JSWebAssemblyModule> m_module;
+ WriteBarrier<JSModuleNamespaceObject> m_moduleNamespaceObject;
+ WriteBarrier<JSWebAssemblyMemory> m_memory;
+ WriteBarrier<JSWebAssemblyTable> m_table;
+ MallocPtr<uint64_t> m_globals;
+ unsigned m_numImportFunctions;
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.cpp
new file mode 100644
index 000000000..ef52fe8be
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSWebAssemblyLinkError.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCInlines.h"
+
+namespace JSC {
+
+JSWebAssemblyLinkError* JSWebAssemblyLinkError::create(ExecState* state, VM& vm, Structure* structure, const String& message)
+{
+ auto* instance = new (NotNull, allocateCell<JSWebAssemblyLinkError>(vm.heap)) JSWebAssemblyLinkError(vm, structure);
+ instance->m_sourceAppender = defaultSourceAppender;
+ bool useCurrentFrame = true;
+ instance->finishCreation(state, vm, message, useCurrentFrame);
+ return instance;
+}
+
+JSWebAssemblyLinkError::JSWebAssemblyLinkError(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+const ClassInfo JSWebAssemblyLinkError::s_info = { "WebAssembly.LinkError", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssemblyLinkError) };
+
+
+JSObject* createJSWebAssemblyLinkError(ExecState* state, VM& vm, const String& message)
+{
+ ASSERT(!message.isEmpty());
+ JSGlobalObject* globalObject = state->lexicalGlobalObject();
+ return JSWebAssemblyLinkError::create(state, vm, globalObject->WebAssemblyLinkErrorStructure(), message);
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.h b/Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.h
new file mode 100644
index 000000000..f2651eb20
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyLinkError.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "ErrorInstance.h"
+
+namespace JSC {
+
+class JSWebAssemblyLinkError : public ErrorInstance {
+public:
+ typedef ErrorInstance Base;
+
+ static JSWebAssemblyLinkError* create(ExecState*, VM&, Structure*, const String&);
+ static JSWebAssemblyLinkError* create(ExecState* state, VM& vm, Structure* structure, JSValue message)
+ {
+ return create(state, vm, structure, message.isUndefined() ? String() : message.toWTFString(state));
+ }
+
+ DECLARE_INFO;
+
+protected:
+ JSWebAssemblyLinkError(VM&, Structure*);
+};
+
+JSObject* createJSWebAssemblyLinkError(ExecState*, VM&, const String&);
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp
new file mode 100644
index 000000000..f4253b5bf
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.cpp
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSWebAssemblyMemory.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCInlines.h"
+
+#include "ArrayBuffer.h"
+#include "JSArrayBuffer.h"
+
+namespace JSC {
+
+const ClassInfo JSWebAssemblyMemory::s_info = { "WebAssembly.Memory", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssemblyMemory) };
+
+JSWebAssemblyMemory* JSWebAssemblyMemory::create(VM& vm, Structure* structure, Wasm::Memory&& memory)
+{
+ auto* instance = new (NotNull, allocateCell<JSWebAssemblyMemory>(vm.heap)) JSWebAssemblyMemory(vm, structure, std::forward<Wasm::Memory>(memory));
+ instance->finishCreation(vm);
+ return instance;
+}
+
+Structure* JSWebAssemblyMemory::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSWebAssemblyMemory::JSWebAssemblyMemory(VM& vm, Structure* structure, Wasm::Memory&& memory)
+ : Base(vm, structure)
+ , m_memory(WTFMove(memory))
+{
+}
+
+JSArrayBuffer* JSWebAssemblyMemory::buffer(VM& vm, JSGlobalObject* globalObject)
+{
+ if (m_bufferWrapper)
+ return m_bufferWrapper.get();
+
+ auto destructor = [] (void*) {
+ // We don't need to do anything here to destroy the memory.
+ // The ArrayBuffer backing the JSArrayBuffer is only owned by us,
+ // so we guarantee its lifecycle.
+ };
+ m_buffer = ArrayBuffer::createFromBytes(memory()->memory(), memory()->size(), WTFMove(destructor));
+ m_bufferWrapper.set(vm, this, JSArrayBuffer::create(vm, globalObject->m_arrayBufferStructure.get(), m_buffer.get()));
+ RELEASE_ASSERT(m_bufferWrapper);
+ return m_bufferWrapper.get();
+}
+
+Wasm::PageCount JSWebAssemblyMemory::grow(ExecState* exec, uint32_t delta, bool shouldThrowExceptionsOnFailure)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ Wasm::PageCount oldPageCount = memory()->sizeInPages();
+
+ if (!Wasm::PageCount::isValid(delta)) {
+ if (shouldThrowExceptionsOnFailure)
+ throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Memory.grow expects the delta to be a valid page count")));
+ return Wasm::PageCount();
+ }
+
+ Wasm::PageCount newSize = oldPageCount + Wasm::PageCount(delta);
+ if (!newSize) {
+ if (shouldThrowExceptionsOnFailure)
+ throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Memory.grow expects the grown size to be a valid page count")));
+ return Wasm::PageCount();
+ }
+
+ if (delta) {
+ bool success = memory()->grow(newSize);
+ if (!success) {
+ if (shouldThrowExceptionsOnFailure)
+ throwException(exec, throwScope, createOutOfMemoryError(exec));
+ return Wasm::PageCount();
+ }
+ }
+
+ // We need to clear out the old array buffer because it might now be pointing
+ // to stale memory.
+ // Neuter the old array.
+ if (m_buffer) {
+ ArrayBufferContents dummyContents;
+ m_buffer->transferTo(vm, dummyContents);
+ m_buffer = nullptr;
+ m_bufferWrapper.clear();
+ }
+
+ return oldPageCount;
+}
+
+void JSWebAssemblyMemory::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(vm, info()));
+}
+
+void JSWebAssemblyMemory::destroy(JSCell* cell)
+{
+ auto memory = static_cast<JSWebAssemblyMemory*>(cell);
+ ASSERT(memory->classInfo() == info());
+ VM& vm = *memory->vm();
+
+ if (memory->m_buffer) {
+ ArrayBufferContents dummyContents;
+ memory->m_buffer->transferTo(vm, dummyContents);
+ memory->m_buffer = nullptr;
+ }
+
+ memory->JSWebAssemblyMemory::~JSWebAssemblyMemory();
+}
+
+void JSWebAssemblyMemory::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ auto* thisObject = jsCast<JSWebAssemblyMemory*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_bufferWrapper);
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h b/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h
new file mode 100644
index 000000000..fff141570
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyMemory.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+#include "WasmMemory.h"
+#include <wtf/RefPtr.h>
+
+namespace JSC {
+
+class ArrayBuffer;
+class JSArrayBuffer;
+
+class JSWebAssemblyMemory : public JSDestructibleObject {
+public:
+ typedef JSDestructibleObject Base;
+
+ static JSWebAssemblyMemory* create(VM&, Structure*, Wasm::Memory&&);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+ Wasm::Memory* memory() { return &m_memory; }
+ JSArrayBuffer* buffer(VM& vm, JSGlobalObject*);
+ Wasm::PageCount grow(ExecState*, uint32_t delta, bool shouldThrowExceptionsOnFailure);
+
+ static ptrdiff_t offsetOfMemory() { return OBJECT_OFFSETOF(JSWebAssemblyMemory, m_memory) + Wasm::Memory::offsetOfMemory(); }
+ static ptrdiff_t offsetOfSize() { return OBJECT_OFFSETOF(JSWebAssemblyMemory, m_memory) + Wasm::Memory::offsetOfSize(); }
+
+protected:
+ JSWebAssemblyMemory(VM&, Structure*, Wasm::Memory&&);
+ void finishCreation(VM&);
+ static void destroy(JSCell*);
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+ Wasm::Memory m_memory;
+ WriteBarrier<JSArrayBuffer> m_bufferWrapper;
+ RefPtr<ArrayBuffer> m_buffer;
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp
new file mode 100644
index 000000000..08fa58462
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSWebAssemblyModule.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCInlines.h"
+#include "JSWebAssemblyCallee.h"
+#include "WasmFormat.h"
+#include "WasmMemory.h"
+#include <wtf/StdLibExtras.h>
+
+namespace JSC {
+
+const ClassInfo JSWebAssemblyModule::s_info = { "WebAssembly.Module", &Base::s_info, nullptr, CREATE_METHOD_TABLE(JSWebAssemblyModule) };
+
+JSWebAssemblyModule* JSWebAssemblyModule::create(VM& vm, Structure* structure, std::unique_ptr<Wasm::ModuleInformation>&& moduleInformation, Bag<CallLinkInfo>&& callLinkInfos, Vector<Wasm::WasmExitStubs>&& wasmExitStubs, SymbolTable* exportSymbolTable, unsigned calleeCount)
+{
+ auto* instance = new (NotNull, allocateCell<JSWebAssemblyModule>(vm.heap, allocationSize(calleeCount))) JSWebAssemblyModule(vm, structure, std::forward<std::unique_ptr<Wasm::ModuleInformation>>(moduleInformation), std::forward<Bag<CallLinkInfo>>(callLinkInfos), std::forward<Vector<Wasm::WasmExitStubs>>(wasmExitStubs), calleeCount);
+ instance->finishCreation(vm, exportSymbolTable);
+ return instance;
+}
+
+Structure* JSWebAssemblyModule::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSWebAssemblyModule::JSWebAssemblyModule(VM& vm, Structure* structure, std::unique_ptr<Wasm::ModuleInformation>&& moduleInformation, Bag<CallLinkInfo>&& callLinkInfos, Vector<Wasm::WasmExitStubs>&& wasmExitStubs, unsigned calleeCount)
+ : Base(vm, structure)
+ , m_moduleInformation(WTFMove(moduleInformation))
+ , m_callLinkInfos(WTFMove(callLinkInfos))
+ , m_wasmExitStubs(WTFMove(wasmExitStubs))
+ , m_calleeCount(calleeCount)
+{
+ memset(callees(), 0, m_calleeCount * sizeof(WriteBarrier<JSWebAssemblyCallee>) * 2);
+}
+
+void JSWebAssemblyModule::finishCreation(VM& vm, SymbolTable* exportSymbolTable)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(vm, info()));
+ m_exportSymbolTable.set(vm, this, exportSymbolTable);
+}
+
+void JSWebAssemblyModule::destroy(JSCell* cell)
+{
+ static_cast<JSWebAssemblyModule*>(cell)->JSWebAssemblyModule::~JSWebAssemblyModule();
+}
+
+void JSWebAssemblyModule::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ JSWebAssemblyModule* thisObject = jsCast<JSWebAssemblyModule*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_exportSymbolTable);
+ for (unsigned i = 0; i < thisObject->m_calleeCount * 2; i++)
+ visitor.append(thisObject->callees()[i]);
+
+ visitor.addUnconditionalFinalizer(&thisObject->m_unconditionalFinalizer);
+}
+
+void JSWebAssemblyModule::UnconditionalFinalizer::finalizeUnconditionally()
+{
+ JSWebAssemblyModule* thisObject = bitwise_cast<JSWebAssemblyModule*>(
+ bitwise_cast<char*>(this) - OBJECT_OFFSETOF(JSWebAssemblyModule, m_unconditionalFinalizer));
+ for (auto iter = thisObject->m_callLinkInfos.begin(); !!iter; ++iter)
+ (*iter)->visitWeak(*thisObject->vm());
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h b/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h
new file mode 100644
index 000000000..7e051f572
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+#include "JSWebAssemblyCallee.h"
+#include "UnconditionalFinalizer.h"
+#include "WasmFormat.h"
+#include <wtf/Bag.h>
+#include <wtf/Vector.h>
+
+namespace JSC {
+
+class SymbolTable;
+
+class JSWebAssemblyModule : public JSDestructibleObject {
+public:
+ typedef JSDestructibleObject Base;
+
+ static JSWebAssemblyModule* create(VM&, Structure*, std::unique_ptr<Wasm::ModuleInformation>&&, Bag<CallLinkInfo>&&, Vector<Wasm::WasmExitStubs>&&, SymbolTable*, unsigned);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+ const Wasm::ModuleInformation& moduleInformation() const { return *m_moduleInformation.get(); }
+ SymbolTable* exportSymbolTable() const { return m_exportSymbolTable.get(); }
+ Wasm::SignatureIndex signatureIndexFromFunctionIndexSpace(unsigned functionIndexSpace) const
+ {
+ return m_moduleInformation->signatureIndexFromFunctionIndexSpace(functionIndexSpace);
+ }
+ unsigned functionImportCount() const { return m_wasmExitStubs.size(); }
+
+ JSWebAssemblyCallee* jsEntrypointCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
+ {
+ RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
+ unsigned calleeIndex = functionIndexSpace - functionImportCount();
+ RELEASE_ASSERT(calleeIndex < m_calleeCount);
+ return callees()[calleeIndex].get();
+ }
+
+ JSWebAssemblyCallee* wasmEntrypointCalleeFromFunctionIndexSpace(unsigned functionIndexSpace)
+ {
+ RELEASE_ASSERT(functionIndexSpace >= functionImportCount());
+ unsigned calleeIndex = functionIndexSpace - functionImportCount();
+ RELEASE_ASSERT(calleeIndex < m_calleeCount);
+ return callees()[calleeIndex + m_calleeCount].get();
+ }
+
+ void setJSEntrypointCallee(VM& vm, unsigned calleeIndex, JSWebAssemblyCallee* callee)
+ {
+ RELEASE_ASSERT(calleeIndex < m_calleeCount);
+ callees()[calleeIndex].set(vm, this, callee);
+ }
+
+ void setWasmEntrypointCallee(VM& vm, unsigned calleeIndex, JSWebAssemblyCallee* callee)
+ {
+ RELEASE_ASSERT(calleeIndex < m_calleeCount);
+ callees()[calleeIndex + m_calleeCount].set(vm, this, callee);
+ }
+
+ WriteBarrier<JSWebAssemblyCallee>* callees()
+ {
+ return bitwise_cast<WriteBarrier<JSWebAssemblyCallee>*>(bitwise_cast<char*>(this) + offsetOfCallees());
+ }
+
+protected:
+ JSWebAssemblyModule(VM&, Structure*, std::unique_ptr<Wasm::ModuleInformation>&&, Bag<CallLinkInfo>&&, Vector<Wasm::WasmExitStubs>&&, unsigned calleeCount);
+ void finishCreation(VM&, SymbolTable*);
+ static void destroy(JSCell*);
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+private:
+ static size_t offsetOfCallees()
+ {
+ return WTF::roundUpToMultipleOf<sizeof(WriteBarrier<JSWebAssemblyCallee>)>(sizeof(JSWebAssemblyModule));
+ }
+
+ static size_t allocationSize(unsigned numCallees)
+ {
+ return offsetOfCallees() + sizeof(WriteBarrier<JSWebAssemblyCallee>) * numCallees * 2;
+ }
+
+ class UnconditionalFinalizer : public JSC::UnconditionalFinalizer {
+ void finalizeUnconditionally() override;
+ };
+
+ UnconditionalFinalizer m_unconditionalFinalizer;
+ std::unique_ptr<Wasm::ModuleInformation> m_moduleInformation;
+ Bag<CallLinkInfo> m_callLinkInfos;
+ WriteBarrier<SymbolTable> m_exportSymbolTable;
+ Vector<Wasm::WasmExitStubs> m_wasmExitStubs;
+ unsigned m_calleeCount;
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp
new file mode 100644
index 000000000..e212a3776
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSWebAssemblyRuntimeError.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCInlines.h"
+
+namespace JSC {
+
+JSWebAssemblyRuntimeError* JSWebAssemblyRuntimeError::create(ExecState* state, VM& vm, Structure* structure, const String& message)
+{
+ auto* instance = new (NotNull, allocateCell<JSWebAssemblyRuntimeError>(vm.heap)) JSWebAssemblyRuntimeError(vm, structure);
+ instance->m_sourceAppender = defaultSourceAppender;
+ bool useCurrentFrame = true;
+ instance->finishCreation(state, vm, message, useCurrentFrame);
+ return instance;
+}
+
+JSWebAssemblyRuntimeError::JSWebAssemblyRuntimeError(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+const ClassInfo JSWebAssemblyRuntimeError::s_info = { "WebAssembly.RuntimeError", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssemblyRuntimeError) };
+
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.h b/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.h
new file mode 100644
index 000000000..5ac630d0f
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyRuntimeError.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "ErrorInstance.h"
+
+namespace JSC {
+
+class JSWebAssemblyRuntimeError : public ErrorInstance {
+public:
+ typedef ErrorInstance Base;
+
+ static JSWebAssemblyRuntimeError* create(ExecState*, VM&, Structure*, const String&);
+ static JSWebAssemblyRuntimeError* create(ExecState* state, VM& vm, Structure* structure, JSValue message)
+ {
+ return create(state, vm, structure, message.isUndefined() ? String() : message.toWTFString(state));
+ }
+
+ DECLARE_INFO;
+
+protected:
+ JSWebAssemblyRuntimeError(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp b/Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp
new file mode 100644
index 000000000..0aff9b924
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.cpp
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSWebAssemblyTable.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCInlines.h"
+#include "WasmFormat.h"
+
+namespace JSC {
+
+const ClassInfo JSWebAssemblyTable::s_info = { "WebAssembly.Table", &Base::s_info, 0, CREATE_METHOD_TABLE(JSWebAssemblyTable) };
+
+JSWebAssemblyTable* JSWebAssemblyTable::create(ExecState* exec, VM& vm, Structure* structure, uint32_t initial, std::optional<uint32_t> maximum)
+{
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ if (!isValidSize(initial)) {
+ throwException(exec, throwScope, createOutOfMemoryError(exec));
+ return nullptr;
+ }
+
+ auto* instance = new (NotNull, allocateCell<JSWebAssemblyTable>(vm.heap)) JSWebAssemblyTable(vm, structure, initial, maximum);
+ instance->finishCreation(vm);
+ return instance;
+}
+
+Structure* JSWebAssemblyTable::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+JSWebAssemblyTable::JSWebAssemblyTable(VM& vm, Structure* structure, uint32_t initial, std::optional<uint32_t> maximum)
+ : Base(vm, structure)
+{
+ m_size = initial;
+ ASSERT(isValidSize(m_size));
+ m_maximum = maximum;
+ ASSERT(!m_maximum || *m_maximum >= m_size);
+
+ // FIXME: It might be worth trying to pre-allocate maximum here. The spec recommends doing so.
+ // But for now, we're not doing that.
+ m_functions = MallocPtr<Wasm::CallableFunction>::malloc(sizeof(Wasm::CallableFunction) * static_cast<size_t>(m_size));
+ m_jsFunctions = MallocPtr<WriteBarrier<WebAssemblyFunction>>::malloc(sizeof(WriteBarrier<WebAssemblyFunction>) * static_cast<size_t>(m_size));
+ for (uint32_t i = 0; i < m_size; ++i) {
+ new (&m_functions.get()[i]) Wasm::CallableFunction();
+ ASSERT(m_functions.get()[i].signatureIndex == Wasm::Signature::invalidIndex); // We rely on this in compiled code.
+ new (&m_jsFunctions.get()[i]) WriteBarrier<WebAssemblyFunction>();
+ }
+}
+
+void JSWebAssemblyTable::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+ ASSERT(inherits(vm, info()));
+}
+
+void JSWebAssemblyTable::destroy(JSCell* cell)
+{
+ static_cast<JSWebAssemblyTable*>(cell)->JSWebAssemblyTable::~JSWebAssemblyTable();
+}
+
+void JSWebAssemblyTable::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ JSWebAssemblyTable* thisObject = jsCast<JSWebAssemblyTable*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+
+ Base::visitChildren(thisObject, visitor);
+
+ for (unsigned i = 0; i < thisObject->m_size; ++i)
+ visitor.append(thisObject->m_jsFunctions.get()[i]);
+}
+
+bool JSWebAssemblyTable::grow(uint32_t newSize)
+{
+ if (newSize < m_size)
+ return false;
+ if (newSize == m_size)
+ return true;
+ if (maximum() && newSize > *maximum())
+ return false;
+ if (!isValidSize(newSize))
+ return false;
+
+ m_functions.realloc(sizeof(Wasm::CallableFunction) * static_cast<size_t>(newSize));
+ m_jsFunctions.realloc(sizeof(WriteBarrier<WebAssemblyFunction>) * static_cast<size_t>(newSize));
+
+ for (uint32_t i = m_size; i < newSize; ++i) {
+ new (&m_functions.get()[i]) Wasm::CallableFunction();
+ new (&m_jsFunctions.get()[i]) WriteBarrier<WebAssemblyFunction>();
+ }
+ m_size = newSize;
+ return true;
+}
+
+void JSWebAssemblyTable::clearFunction(uint32_t index)
+{
+ RELEASE_ASSERT(index < m_size);
+ m_jsFunctions.get()[index] = WriteBarrier<WebAssemblyFunction>();
+ m_functions.get()[index] = Wasm::CallableFunction();
+ ASSERT(m_functions.get()[index].signatureIndex == Wasm::Signature::invalidIndex); // We rely on this in compiled code.
+}
+
+void JSWebAssemblyTable::setFunction(VM& vm, uint32_t index, WebAssemblyFunction* function)
+{
+ RELEASE_ASSERT(index < m_size);
+ m_jsFunctions.get()[index].set(vm, this, function);
+ m_functions.get()[index] = Wasm::CallableFunction(function->signatureIndex(), function->wasmEntrypoint());
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h b/Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h
new file mode 100644
index 000000000..468a027ce
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/JSWebAssemblyTable.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+#include "WebAssemblyFunction.h"
+#include <wtf/MallocPtr.h>
+
+namespace JSC {
+
+namespace Wasm {
+struct CallableFunction;
+}
+
+class JSWebAssemblyTable : public JSDestructibleObject {
+public:
+ typedef JSDestructibleObject Base;
+
+ static JSWebAssemblyTable* create(ExecState*, VM&, Structure*, uint32_t initial, std::optional<uint32_t> maximum);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+ std::optional<uint32_t> maximum() const { return m_maximum; }
+ uint32_t size() const { return m_size; }
+ bool grow(uint32_t newSize) WARN_UNUSED_RETURN;
+ WebAssemblyFunction* getFunction(uint32_t index)
+ {
+ RELEASE_ASSERT(index < m_size);
+ return m_jsFunctions.get()[index].get();
+ }
+ void clearFunction(uint32_t index);
+ void setFunction(VM&, uint32_t index, WebAssemblyFunction*);
+
+ static ptrdiff_t offsetOfSize() { return OBJECT_OFFSETOF(JSWebAssemblyTable, m_size); }
+ static ptrdiff_t offsetOfFunctions() { return OBJECT_OFFSETOF(JSWebAssemblyTable, m_functions); }
+
+ static bool isValidSize(uint32_t size)
+ {
+ // This tops out at ~384 MB worth of data in this class.
+ return size < (1 << 24);
+ }
+
+private:
+ JSWebAssemblyTable(VM&, Structure*, uint32_t initial, std::optional<uint32_t> maximum);
+ void finishCreation(VM&);
+ static void destroy(JSCell*);
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+ MallocPtr<Wasm::CallableFunction> m_functions;
+ MallocPtr<WriteBarrier<WebAssemblyFunction>> m_jsFunctions;
+ std::optional<uint32_t> m_maximum;
+ uint32_t m_size;
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.cpp
new file mode 100644
index 000000000..40effb65f
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyCompileErrorConstructor.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+#include "JSWebAssemblyCompileError.h"
+#include "WebAssemblyCompileErrorPrototype.h"
+
+#include "WebAssemblyCompileErrorConstructor.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyCompileErrorConstructor::s_info = { "Function", &Base::s_info, &constructorTableWebAssemblyCompileError, CREATE_METHOD_TABLE(WebAssemblyCompileErrorConstructor) };
+
+/* Source for WebAssemblyCompileErrorConstructor.lut.h
+ @begin constructorTableWebAssemblyCompileError
+ @end
+ */
+
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyCompileError(ExecState* state)
+{
+ auto& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ JSValue message = state->argument(0);
+ auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyCompileErrorStructure());
+ RETURN_IF_EXCEPTION(scope, encodedJSValue());
+ return JSValue::encode(JSWebAssemblyCompileError::create(state, vm, structure, message));
+}
+
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyCompileError(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.CompileError"));
+}
+
+WebAssemblyCompileErrorConstructor* WebAssemblyCompileErrorConstructor::create(VM& vm, Structure* structure, WebAssemblyCompileErrorPrototype* thisPrototype)
+{
+ auto* constructor = new (NotNull, allocateCell<WebAssemblyCompileErrorConstructor>(vm.heap)) WebAssemblyCompileErrorConstructor(vm, structure);
+ constructor->finishCreation(vm, thisPrototype);
+ return constructor;
+}
+
+Structure* WebAssemblyCompileErrorConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyCompileErrorConstructor::finishCreation(VM& vm, WebAssemblyCompileErrorPrototype* prototype)
+{
+ Base::finishCreation(vm, ASCIILiteral("CompileError"));
+ putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, ReadOnly | DontEnum | DontDelete);
+ putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
+}
+
+WebAssemblyCompileErrorConstructor::WebAssemblyCompileErrorConstructor(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+ConstructType WebAssemblyCompileErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
+{
+ constructData.native.function = constructJSWebAssemblyCompileError;
+ return ConstructType::Host;
+}
+
+CallType WebAssemblyCompileErrorConstructor::getCallData(JSCell*, CallData& callData)
+{
+ callData.native.function = callJSWebAssemblyCompileError;
+ return CallType::Host;
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.h b/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.h
new file mode 100644
index 000000000..34a0e78c0
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorConstructor.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "InternalFunction.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyCompileErrorPrototype;
+
+class WebAssemblyCompileErrorConstructor : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyCompileErrorConstructor* create(VM&, Structure*, WebAssemblyCompileErrorPrototype*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&, WebAssemblyCompileErrorPrototype*);
+
+private:
+ WebAssemblyCompileErrorConstructor(VM&, Structure*);
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorPrototype.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorPrototype.cpp
new file mode 100644
index 000000000..0522e1f30
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorPrototype.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyCompileErrorPrototype.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+
+#include "WebAssemblyCompileErrorPrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyCompileErrorPrototype::s_info = { "WebAssembly.CompileError.prototype", &Base::s_info, &prototypeTableWebAssemblyCompileError, CREATE_METHOD_TABLE(WebAssemblyCompileErrorPrototype) };
+
+/* Source for WebAssemblyCompileErrorPrototype.lut.h
+ @begin prototypeTableWebAssemblyCompileError
+ @end
+ */
+
+WebAssemblyCompileErrorPrototype* WebAssemblyCompileErrorPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
+{
+ auto* object = new (NotNull, allocateCell<WebAssemblyCompileErrorPrototype>(vm.heap)) WebAssemblyCompileErrorPrototype(vm, structure);
+ object->finishCreation(vm);
+ return object;
+}
+
+Structure* WebAssemblyCompileErrorPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyCompileErrorPrototype::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+}
+
+WebAssemblyCompileErrorPrototype::WebAssemblyCompileErrorPrototype(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorPrototype.h b/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorPrototype.h
new file mode 100644
index 000000000..d3296513a
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyCompileErrorPrototype.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyCompileErrorPrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyCompileErrorPrototype* create(VM&, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&);
+
+private:
+ WebAssemblyCompileErrorPrototype(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
new file mode 100644
index 000000000..5ae817f4f
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyFunction.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "B3Compilation.h"
+#include "JSCInlines.h"
+#include "JSFunctionInlines.h"
+#include "JSObject.h"
+#include "JSWebAssemblyCallee.h"
+#include "JSWebAssemblyInstance.h"
+#include "JSWebAssemblyMemory.h"
+#include "JSWebAssemblyRuntimeError.h"
+#include "LLIntThunks.h"
+#include "ProtoCallFrame.h"
+#include "VM.h"
+#include "WasmFormat.h"
+#include "WasmMemory.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyFunction::s_info = { "WebAssemblyFunction", &Base::s_info, nullptr, CREATE_METHOD_TABLE(WebAssemblyFunction) };
+
+static EncodedJSValue JSC_HOST_CALL callWebAssemblyFunction(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ WebAssemblyFunction* wasmFunction = jsDynamicCast<WebAssemblyFunction*>(vm, exec->jsCallee());
+ if (!wasmFunction)
+ return JSValue::encode(throwException(exec, scope, createTypeError(exec, "expected a WebAssembly function", defaultSourceAppender, runtimeTypeForValue(exec->jsCallee()))));
+ Wasm::SignatureIndex signatureIndex = wasmFunction->signatureIndex();
+ const Wasm::Signature* signature = Wasm::SignatureInformation::get(&vm, signatureIndex);
+
+ {
+ // Check if we have a disallowed I64 use.
+
+ for (unsigned argIndex = 0; argIndex < signature->argumentCount(); ++argIndex) {
+ if (signature->argument(argIndex) == Wasm::I64) {
+ JSWebAssemblyRuntimeError* error = JSWebAssemblyRuntimeError::create(exec, vm, exec->lexicalGlobalObject()->WebAssemblyRuntimeErrorStructure(),
+ "WebAssembly function with an i64 argument can't be called from JavaScript");
+ return JSValue::encode(throwException(exec, scope, error));
+ }
+ }
+
+ if (signature->returnType() == Wasm::I64) {
+ JSWebAssemblyRuntimeError* error = JSWebAssemblyRuntimeError::create(exec, vm, exec->lexicalGlobalObject()->WebAssemblyRuntimeErrorStructure(),
+ "WebAssembly function that returns i64 can't be called from JavaScript");
+ return JSValue::encode(throwException(exec, scope, error));
+ }
+ }
+
+ Vector<JSValue> boxedArgs;
+ for (unsigned argIndex = 0; argIndex < signature->argumentCount(); ++argIndex) {
+ JSValue arg = exec->argument(argIndex);
+ switch (signature->argument(argIndex)) {
+ case Wasm::I32:
+ arg = JSValue::decode(arg.toInt32(exec));
+ break;
+ case Wasm::F32:
+ arg = JSValue::decode(bitwise_cast<uint32_t>(arg.toFloat(exec)));
+ break;
+ case Wasm::F64:
+ arg = JSValue::decode(bitwise_cast<uint64_t>(arg.toNumber(exec)));
+ break;
+ case Wasm::Void:
+ case Wasm::I64:
+ case Wasm::Func:
+ case Wasm::Anyfunc:
+ RELEASE_ASSERT_NOT_REACHED();
+ }
+ RETURN_IF_EXCEPTION(scope, encodedJSValue());
+ boxedArgs.append(arg);
+ }
+
+ JSValue firstArgument = JSValue();
+ int argCount = 1;
+ JSValue* remainingArgs = nullptr;
+ if (boxedArgs.size()) {
+ remainingArgs = boxedArgs.data();
+ firstArgument = *remainingArgs;
+ remainingArgs++;
+ argCount = boxedArgs.size();
+ }
+
+ // Note: we specifically use the WebAssemblyFunction as the callee to begin with in the ProtoCallFrame.
+ // The reason for this is that calling into the llint may stack overflow, and the stack overflow
+ // handler might read the global object from the callee. The JSWebAssemblyCallee doesn't have a
+ // global object, but the WebAssemblyFunction does.
+ ProtoCallFrame protoCallFrame;
+ protoCallFrame.init(nullptr, wasmFunction, firstArgument, argCount, remainingArgs);
+
+ // FIXME Do away with this entire function, and only use the entrypoint generated by B3. https://bugs.webkit.org/show_bug.cgi?id=166486
+ JSWebAssemblyInstance* prevJSWebAssemblyInstance = vm.topJSWebAssemblyInstance;
+ vm.topJSWebAssemblyInstance = wasmFunction->instance();
+ ASSERT(wasmFunction->instance());
+ EncodedJSValue rawResult = vmEntryToWasm(wasmFunction->jsEntrypoint(), &vm, &protoCallFrame);
+ vm.topJSWebAssemblyInstance = prevJSWebAssemblyInstance;
+ RETURN_IF_EXCEPTION(scope, { });
+
+ switch (signature->returnType()) {
+ case Wasm::Void:
+ return JSValue::encode(jsUndefined());
+ case Wasm::I32:
+ return JSValue::encode(jsNumber(static_cast<int32_t>(rawResult)));
+ case Wasm::F32:
+ return JSValue::encode(jsNumber(purifyNaN(static_cast<double>(bitwise_cast<float>(static_cast<int32_t>(rawResult))))));
+ case Wasm::F64:
+ return JSValue::encode(jsNumber(purifyNaN(bitwise_cast<double>(rawResult))));
+ case Wasm::I64:
+ case Wasm::Func:
+ case Wasm::Anyfunc:
+ RELEASE_ASSERT_NOT_REACHED();
+ }
+
+ return EncodedJSValue();
+}
+
+WebAssemblyFunction* WebAssemblyFunction::create(VM& vm, JSGlobalObject* globalObject, unsigned length, const String& name, JSWebAssemblyInstance* instance, JSWebAssemblyCallee* jsEntrypoint, JSWebAssemblyCallee* wasmEntrypoint, Wasm::SignatureIndex signatureIndex)
+{
+ NativeExecutable* executable = vm.getHostFunction(callWebAssemblyFunction, NoIntrinsic, callHostFunctionAsConstructor, nullptr, name);
+ Structure* structure = globalObject->webAssemblyFunctionStructure();
+ WebAssemblyFunction* function = new (NotNull, allocateCell<WebAssemblyFunction>(vm.heap)) WebAssemblyFunction(vm, globalObject, structure, wasmEntrypoint, signatureIndex);
+ function->finishCreation(vm, executable, length, name, instance, jsEntrypoint, wasmEntrypoint);
+ return function;
+}
+
+Structure* WebAssemblyFunction::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ ASSERT(globalObject);
+ return Structure::create(vm, globalObject, prototype, TypeInfo(WebAssemblyFunctionType, StructureFlags), info());
+}
+
+WebAssemblyFunction::WebAssemblyFunction(VM& vm, JSGlobalObject* globalObject, Structure* structure, JSWebAssemblyCallee* wasmEntrypoint, Wasm::SignatureIndex signatureIndex)
+ : Base(vm, globalObject, structure)
+ , m_wasmEntryPointCode(wasmEntrypoint->entrypoint())
+ , m_signatureIndex(signatureIndex)
+{ }
+
+void WebAssemblyFunction::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ WebAssemblyFunction* thisObject = jsCast<WebAssemblyFunction*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_instance);
+ visitor.append(thisObject->m_jsEntrypoint);
+ visitor.append(thisObject->m_wasmEntrypoint);
+}
+
+void WebAssemblyFunction::finishCreation(VM& vm, NativeExecutable* executable, unsigned length, const String& name, JSWebAssemblyInstance* instance, JSWebAssemblyCallee* jsEntrypoint, JSWebAssemblyCallee* wasmEntrypoint)
+{
+ Base::finishCreation(vm, executable, length, name);
+ ASSERT(inherits(vm, info()));
+ m_instance.set(vm, this, instance);
+ ASSERT(jsEntrypoint != wasmEntrypoint);
+ m_jsEntrypoint.set(vm, this, jsEntrypoint);
+ m_wasmEntrypoint.set(vm, this, wasmEntrypoint);
+ ASSERT(m_wasmEntrypoint->entrypoint() == m_wasmEntryPointCode);
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.h b/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.h
new file mode 100644
index 000000000..26694c16d
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyFunction.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSFunction.h"
+#include "JSWebAssemblyCallee.h"
+#include <wtf/Noncopyable.h>
+
+namespace JSC {
+
+class JSGlobalObject;
+struct ProtoCallFrame;
+class WebAssemblyInstance;
+
+namespace B3 {
+class Compilation;
+}
+
+class WebAssemblyFunction : public JSFunction {
+public:
+ typedef JSFunction Base;
+
+ const static unsigned StructureFlags = Base::StructureFlags;
+
+ DECLARE_EXPORT_INFO;
+
+ JS_EXPORT_PRIVATE static WebAssemblyFunction* create(VM&, JSGlobalObject*, unsigned, const String&, JSWebAssemblyInstance*, JSWebAssemblyCallee* jsEntrypoint, JSWebAssemblyCallee* wasmEntrypoint, Wasm::SignatureIndex);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ JSWebAssemblyInstance* instance() const { return m_instance.get(); }
+ Wasm::SignatureIndex signatureIndex() const { return m_signatureIndex; }
+ void* wasmEntrypoint() { return m_wasmEntryPointCode; }
+ void* jsEntrypoint() { return m_jsEntrypoint->entrypoint(); }
+
+ static ptrdiff_t offsetOfInstance() { return OBJECT_OFFSETOF(WebAssemblyFunction, m_instance); }
+ static ptrdiff_t offsetOfWasmEntryPointCode() { return OBJECT_OFFSETOF(WebAssemblyFunction, m_wasmEntryPointCode); }
+
+protected:
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+ void finishCreation(VM&, NativeExecutable*, unsigned length, const String& name, JSWebAssemblyInstance*, JSWebAssemblyCallee* jsEntrypoint, JSWebAssemblyCallee* wasmEntrypoint);
+
+private:
+ WebAssemblyFunction(VM&, JSGlobalObject*, Structure*, JSWebAssemblyCallee*, Wasm::SignatureIndex);
+
+ WriteBarrier<JSWebAssemblyInstance> m_instance;
+ void* m_wasmEntryPointCode; // Cache code pointer: allows the wasm -> wasm stub to do a single load and jump instead of having dependent loads.
+ WriteBarrier<JSWebAssemblyCallee> m_jsEntrypoint;
+ WriteBarrier<JSWebAssemblyCallee> m_wasmEntrypoint;
+ Wasm::SignatureIndex m_signatureIndex;
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyFunctionCell.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyFunctionCell.cpp
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyFunctionCell.cpp
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyFunctionCell.h b/Source/JavaScriptCore/wasm/js/WebAssemblyFunctionCell.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyFunctionCell.h
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp
new file mode 100644
index 000000000..763dc494c
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.cpp
@@ -0,0 +1,345 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyInstanceConstructor.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+#include "JSModuleEnvironment.h"
+#include "JSModuleNamespaceObject.h"
+#include "JSWebAssemblyInstance.h"
+#include "JSWebAssemblyLinkError.h"
+#include "JSWebAssemblyMemory.h"
+#include "JSWebAssemblyModule.h"
+#include "WebAssemblyFunction.h"
+#include "WebAssemblyInstancePrototype.h"
+#include "WebAssemblyModuleRecord.h"
+
+#include "WebAssemblyInstanceConstructor.lut.h"
+
+namespace JSC {
+
+static const bool verbose = false;
+
+const ClassInfo WebAssemblyInstanceConstructor::s_info = { "Function", &Base::s_info, &constructorTableWebAssemblyInstance, CREATE_METHOD_TABLE(WebAssemblyInstanceConstructor) };
+
+/* Source for WebAssemblyInstanceConstructor.lut.h
+ @begin constructorTableWebAssemblyInstance
+ @end
+ */
+
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyInstance(ExecState* exec)
+{
+ auto& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* globalObject = exec->lexicalGlobalObject();
+
+ // If moduleObject is not a WebAssembly.Module instance, a TypeError is thrown.
+ JSWebAssemblyModule* jsModule = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->argument(0));
+ if (!jsModule)
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("first argument to WebAssembly.Instance must be a WebAssembly.Module"), defaultSourceAppender, runtimeTypeForValue(exec->argument(0)))));
+ const Wasm::ModuleInformation& moduleInformation = jsModule->moduleInformation();
+
+ // If the importObject parameter is not undefined and Type(importObject) is not Object, a TypeError is thrown.
+ JSValue importArgument = exec->argument(1);
+ JSObject* importObject = importArgument.getObject();
+ if (!importArgument.isUndefined() && !importObject)
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("second argument to WebAssembly.Instance must be undefined or an Object"), defaultSourceAppender, runtimeTypeForValue(importArgument))));
+
+ // If the list of module.imports is not empty and Type(importObject) is not Object, a TypeError is thrown.
+ if (moduleInformation.imports.size() && !importObject)
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("second argument to WebAssembly.Instance must be Object because the WebAssembly.Module has imports"), defaultSourceAppender, runtimeTypeForValue(importArgument))));
+
+ Identifier moduleKey = Identifier::fromUid(PrivateName(PrivateName::Description, "WebAssemblyInstance"));
+ WebAssemblyModuleRecord* moduleRecord = WebAssemblyModuleRecord::create(exec, vm, globalObject->webAssemblyModuleRecordStructure(), moduleKey, moduleInformation);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ Structure* instanceStructure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), globalObject->WebAssemblyInstanceStructure());
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ JSWebAssemblyInstance* instance = JSWebAssemblyInstance::create(vm, instanceStructure, jsModule, moduleRecord->getModuleNamespace(exec));
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ {
+ // Always start with a dummy Memory, so that wasm -> wasm thunks avoid checking for a nullptr Memory when trying to set pinned registers.
+ Wasm::Memory memory;
+ instance->setMemory(vm, JSWebAssemblyMemory::create(vm, exec->lexicalGlobalObject()->WebAssemblyMemoryStructure(), WTFMove(memory)));
+ }
+
+ // Let funcs, memories and tables be initially-empty lists of callable JavaScript objects, WebAssembly.Memory objects and WebAssembly.Table objects, respectively.
+ // Let imports be an initially-empty list of external values.
+ unsigned numImportFunctions = 0;
+ unsigned numImportGlobals = 0;
+
+ bool hasMemoryImport = false;
+ bool hasTableImport = false;
+ // For each import i in module.imports:
+ for (auto& import : moduleInformation.imports) {
+ // 1. Let o be the resultant value of performing Get(importObject, i.module_name).
+ JSValue importModuleValue = importObject->get(exec, import.module);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ // 2. If Type(o) is not Object, throw a TypeError.
+ if (!importModuleValue.isObject())
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("import must be an object"), defaultSourceAppender, runtimeTypeForValue(importModuleValue))));
+
+ // 3. Let v be the value of performing Get(o, i.item_name)
+ JSObject* object = jsCast<JSObject*>(importModuleValue);
+ JSValue value = object->get(exec, import.field);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ switch (import.kind) {
+ case Wasm::ExternalKind::Function: {
+ // 4. If i is a function import:
+ // i. If IsCallable(v) is false, throw a WebAssembly.LinkError.
+ if (!value.isFunction())
+ return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("import function must be callable"))));
+ JSCell* cell = value.asCell();
+ // ii. If v is an Exported Function Exotic Object:
+ if (WebAssemblyFunction* importedExport = jsDynamicCast<WebAssemblyFunction*>(vm, cell)) {
+ // a. If the signature of v does not match the signature of i, throw a WebAssembly.LinkError.
+ Wasm::SignatureIndex importedSignatureIndex = importedExport->signatureIndex();
+ Wasm::SignatureIndex expectedSignatureIndex = moduleInformation.importFunctionSignatureIndices[import.kindIndex];
+ if (importedSignatureIndex != expectedSignatureIndex)
+ return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("imported function's signature doesn't match the provided WebAssembly function's signature"))));
+ // b. Let closure be v.[[Closure]].
+ }
+ // iii. Otherwise:
+ // a. Let closure be a new host function of the given signature which calls v by coercing WebAssembly arguments to JavaScript arguments via ToJSValue and returns the result, if any, by coercing via ToWebAssemblyValue.
+ // Note: done as part of Plan compilation.
+ // iv. Append v to funcs.
+ // Note: adding the JSCell to the instance list fulfills closure requirements b. above (the WebAssembly.Instance wil be kept alive) and v. below (the JSFunction).
+ instance->setImportFunction(vm, cell, numImportFunctions++);
+ // v. Append closure to imports.
+ break;
+ }
+ case Wasm::ExternalKind::Table: {
+ RELEASE_ASSERT(!hasTableImport); // This should be guaranteed by a validation failure.
+ // 7. Otherwise (i is a table import):
+ hasTableImport = true;
+ JSWebAssemblyTable* table = jsDynamicCast<JSWebAssemblyTable*>(vm, value);
+ // i. If v is not a WebAssembly.Table object, throw a WebAssembly.LinkError.
+ if (!table)
+ return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Table import is not an instance of WebAssembly.Table"))));
+
+ uint32_t expectedInitial = moduleInformation.tableInformation.initial();
+ uint32_t actualInitial = table->size();
+ if (actualInitial < expectedInitial)
+ return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Table import provided an 'initial' that is too small"))));
+
+ if (std::optional<uint32_t> expectedMaximum = moduleInformation.tableInformation.maximum()) {
+ std::optional<uint32_t> actualMaximum = table->maximum();
+ if (!actualMaximum) {
+ return JSValue::encode(
+ throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Table import does not have a 'maximum' but the module requires that it does"))));
+ }
+ if (*actualMaximum > *expectedMaximum) {
+ return JSValue::encode(
+ throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Imported Table's 'maximum' is larger than the module's expected 'maximum'"))));
+ }
+ }
+
+ // ii. Append v to tables.
+ // iii. Append v.[[Table]] to imports.
+ instance->setTable(vm, table);
+ break;
+ }
+ case Wasm::ExternalKind::Memory: {
+ // 6. If i is a memory import:
+ RELEASE_ASSERT(!hasMemoryImport); // This should be guaranteed by a validation failure.
+ RELEASE_ASSERT(moduleInformation.memory);
+ hasMemoryImport = true;
+ JSWebAssemblyMemory* memory = jsDynamicCast<JSWebAssemblyMemory*>(vm, value);
+ // i. If v is not a WebAssembly.Memory object, throw a WebAssembly.LinkError.
+ if (!memory)
+ return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Memory import is not an instance of WebAssembly.Memory"))));
+
+ Wasm::PageCount expectedInitial = moduleInformation.memory.initial();
+ Wasm::PageCount actualInitial = memory->memory()->initial();
+ if (actualInitial < expectedInitial)
+ return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Memory import provided an 'initial' that is too small"))));
+
+ if (Wasm::PageCount expectedMaximum = moduleInformation.memory.maximum()) {
+ Wasm::PageCount actualMaximum = memory->memory()->maximum();
+ if (!actualMaximum) {
+ return JSValue::encode(
+ throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Memory import did not have a 'maximum' but the module requires that it does"))));
+ }
+
+ if (actualMaximum > expectedMaximum) {
+ return JSValue::encode(
+ throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("Memory imports 'maximum' is larger than the module's expected 'maximum'"))));
+ }
+ }
+ // ii. Append v to memories.
+ // iii. Append v.[[Memory]] to imports.
+ instance->setMemory(vm, memory);
+ break;
+ }
+ case Wasm::ExternalKind::Global: {
+ // 5. If i is a global import:
+ // i. If i is not an immutable global, throw a TypeError.
+ ASSERT(moduleInformation.globals[import.kindIndex].mutability == Wasm::Global::Immutable);
+ // ii. If Type(v) is not Number, throw a TypeError.
+ if (!value.isNumber())
+ return JSValue::encode(throwException(exec, throwScope, createJSWebAssemblyLinkError(exec, vm, ASCIILiteral("imported global must be a number"))));
+ // iii. Append ToWebAssemblyValue(v) to imports.
+ switch (moduleInformation.globals[import.kindIndex].type) {
+ case Wasm::I32:
+ instance->setGlobal(numImportGlobals++, value.toInt32(exec));
+ break;
+ case Wasm::F32:
+ instance->setGlobal(numImportGlobals++, bitwise_cast<uint32_t>(value.toFloat(exec)));
+ break;
+ case Wasm::F64:
+ instance->setGlobal(numImportGlobals++, bitwise_cast<uint64_t>(value.asNumber()));
+ break;
+ default:
+ RELEASE_ASSERT_NOT_REACHED();
+ }
+ ASSERT(!throwScope.exception());
+ break;
+ }
+ }
+ }
+
+ {
+ if (!!moduleInformation.memory && moduleInformation.memory.isImport()) {
+ // We should either have a Memory import or we should have thrown an exception.
+ RELEASE_ASSERT(hasMemoryImport);
+ }
+
+ if (moduleInformation.memory && !hasMemoryImport) {
+ RELEASE_ASSERT(!moduleInformation.memory.isImport());
+ // We create a memory when it's a memory definition.
+ bool failed;
+ Wasm::Memory memory(moduleInformation.memory.initial(), moduleInformation.memory.maximum(), failed);
+ if (failed)
+ return JSValue::encode(throwException(exec, throwScope, createOutOfMemoryError(exec)));
+ instance->setMemory(vm,
+ JSWebAssemblyMemory::create(vm, exec->lexicalGlobalObject()->WebAssemblyMemoryStructure(), WTFMove(memory)));
+ }
+ }
+
+ {
+ if (!!moduleInformation.tableInformation && moduleInformation.tableInformation.isImport()) {
+ // We should either have a Table import or we should have thrown an exception.
+ RELEASE_ASSERT(hasTableImport);
+ }
+
+ if (!!moduleInformation.tableInformation && !hasTableImport) {
+ RELEASE_ASSERT(!moduleInformation.tableInformation.isImport());
+ // We create a Table when it's a Table definition.
+ JSWebAssemblyTable* table = JSWebAssemblyTable::create(exec, vm, exec->lexicalGlobalObject()->WebAssemblyTableStructure(),
+ moduleInformation.tableInformation.initial(), moduleInformation.tableInformation.maximum());
+ // We should always be able to allocate a JSWebAssemblyTable we've defined.
+ // If it's defined to be too large, we should have thrown a validation error.
+ ASSERT(!throwScope.exception());
+ ASSERT(table);
+ instance->setTable(vm, table);
+ }
+ }
+
+ // Globals
+ {
+ ASSERT(numImportGlobals == moduleInformation.firstInternalGlobal);
+ for (size_t globalIndex = numImportGlobals; globalIndex < moduleInformation.globals.size(); ++globalIndex) {
+ const auto& global = moduleInformation.globals[globalIndex];
+ ASSERT(global.initializationType != Wasm::Global::IsImport);
+ if (global.initializationType == Wasm::Global::FromGlobalImport) {
+ ASSERT(global.initialBitsOrImportNumber < numImportGlobals);
+ instance->setGlobal(globalIndex, instance->loadI64Global(global.initialBitsOrImportNumber));
+ } else
+ instance->setGlobal(globalIndex, global.initialBitsOrImportNumber);
+ }
+ }
+
+ moduleRecord->link(exec, instance);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ if (verbose)
+ moduleRecord->dump();
+ JSValue startResult = moduleRecord->evaluate(exec);
+ UNUSED_PARAM(startResult);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ return JSValue::encode(instance);
+}
+
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyInstance(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.Instance"));
+}
+
+WebAssemblyInstanceConstructor* WebAssemblyInstanceConstructor::create(VM& vm, Structure* structure, WebAssemblyInstancePrototype* thisPrototype)
+{
+ auto* constructor = new (NotNull, allocateCell<WebAssemblyInstanceConstructor>(vm.heap)) WebAssemblyInstanceConstructor(vm, structure);
+ constructor->finishCreation(vm, thisPrototype);
+ return constructor;
+}
+
+Structure* WebAssemblyInstanceConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyInstanceConstructor::finishCreation(VM& vm, WebAssemblyInstancePrototype* prototype)
+{
+ Base::finishCreation(vm, ASCIILiteral("Instance"));
+ putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, DontEnum | DontDelete | ReadOnly);
+ putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
+}
+
+WebAssemblyInstanceConstructor::WebAssemblyInstanceConstructor(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+ConstructType WebAssemblyInstanceConstructor::getConstructData(JSCell*, ConstructData& constructData)
+{
+ constructData.native.function = constructJSWebAssemblyInstance;
+ return ConstructType::Host;
+}
+
+CallType WebAssemblyInstanceConstructor::getCallData(JSCell*, CallData& callData)
+{
+ callData.native.function = callJSWebAssemblyInstance;
+ return CallType::Host;
+}
+
+void WebAssemblyInstanceConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ auto* thisObject = jsCast<WebAssemblyInstanceConstructor*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
+
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.h b/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.h
new file mode 100644
index 000000000..2e857cfc4
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyInstanceConstructor.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "InternalFunction.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyInstancePrototype;
+
+class WebAssemblyInstanceConstructor : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyInstanceConstructor* create(VM&, Structure*, WebAssemblyInstancePrototype*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&, WebAssemblyInstancePrototype*);
+
+private:
+ WebAssemblyInstanceConstructor(VM&, Structure*);
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
+ static void visitChildren(JSCell*, SlotVisitor&);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.cpp
new file mode 100644
index 000000000..4777a61c1
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyInstancePrototype.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+
+#include "WebAssemblyInstancePrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyInstancePrototype::s_info = { "WebAssembly.Instance.prototype", &Base::s_info, &prototypeTableWebAssemblyInstance, CREATE_METHOD_TABLE(WebAssemblyInstancePrototype) };
+
+/* Source for WebAssemblyInstancePrototype.lut.h
+ @begin prototypeTableWebAssemblyInstance
+ @end
+ */
+
+WebAssemblyInstancePrototype* WebAssemblyInstancePrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
+{
+ auto* object = new (NotNull, allocateCell<WebAssemblyInstancePrototype>(vm.heap)) WebAssemblyInstancePrototype(vm, structure);
+ object->finishCreation(vm);
+ return object;
+}
+
+Structure* WebAssemblyInstancePrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyInstancePrototype::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+}
+
+WebAssemblyInstancePrototype::WebAssemblyInstancePrototype(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.h b/Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.h
new file mode 100644
index 000000000..ebdbe985a
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyInstancePrototype.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyInstancePrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyInstancePrototype* create(VM&, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&);
+
+private:
+ WebAssemblyInstancePrototype(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.cpp
new file mode 100644
index 000000000..ed0743bde
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyLinkErrorConstructor.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+#include "JSWebAssemblyLinkError.h"
+#include "WebAssemblyLinkErrorPrototype.h"
+
+#include "WebAssemblyLinkErrorConstructor.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyLinkErrorConstructor::s_info = { "Function", &Base::s_info, &constructorTableWebAssemblyLinkError, CREATE_METHOD_TABLE(WebAssemblyLinkErrorConstructor) };
+
+/* Source for WebAssemblyLinkErrorConstructor.lut.h
+ @begin constructorTableWebAssemblyLinkError
+ @end
+ */
+
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyLinkError(ExecState* state)
+{
+ auto& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ JSValue message = state->argument(0);
+ auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyLinkErrorStructure());
+ RETURN_IF_EXCEPTION(scope, encodedJSValue());
+ return JSValue::encode(JSWebAssemblyLinkError::create(state, vm, structure, message));
+}
+
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyLinkError(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.LinkError"));
+}
+
+WebAssemblyLinkErrorConstructor* WebAssemblyLinkErrorConstructor::create(VM& vm, Structure* structure, WebAssemblyLinkErrorPrototype* thisPrototype)
+{
+ auto* constructor = new (NotNull, allocateCell<WebAssemblyLinkErrorConstructor>(vm.heap)) WebAssemblyLinkErrorConstructor(vm, structure);
+ constructor->finishCreation(vm, thisPrototype);
+ return constructor;
+}
+
+Structure* WebAssemblyLinkErrorConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyLinkErrorConstructor::finishCreation(VM& vm, WebAssemblyLinkErrorPrototype* prototype)
+{
+ Base::finishCreation(vm, ASCIILiteral("LinkError"));
+ putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, ReadOnly | DontEnum | DontDelete);
+ putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
+}
+
+WebAssemblyLinkErrorConstructor::WebAssemblyLinkErrorConstructor(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+ConstructType WebAssemblyLinkErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
+{
+ constructData.native.function = constructJSWebAssemblyLinkError;
+ return ConstructType::Host;
+}
+
+CallType WebAssemblyLinkErrorConstructor::getCallData(JSCell*, CallData& callData)
+{
+ callData.native.function = callJSWebAssemblyLinkError;
+ return CallType::Host;
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.h b/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.h
new file mode 100644
index 000000000..c700c6330
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorConstructor.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "InternalFunction.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyLinkErrorPrototype;
+
+class WebAssemblyLinkErrorConstructor : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyLinkErrorConstructor* create(VM&, Structure*, WebAssemblyLinkErrorPrototype*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&, WebAssemblyLinkErrorPrototype*);
+
+private:
+ WebAssemblyLinkErrorConstructor(VM&, Structure*);
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.cpp
new file mode 100644
index 000000000..6860624f5
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyLinkErrorPrototype.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+
+#include "WebAssemblyLinkErrorPrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyLinkErrorPrototype::s_info = { "WebAssembly.LinkError.prototype", &Base::s_info, &prototypeTableWebAssemblyLinkError, CREATE_METHOD_TABLE(WebAssemblyLinkErrorPrototype) };
+
+/* Source for WebAssemblyLinkErrorPrototype.lut.h
+ @begin prototypeTableWebAssemblyLinkError
+ @end
+ */
+
+WebAssemblyLinkErrorPrototype* WebAssemblyLinkErrorPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
+{
+ auto* object = new (NotNull, allocateCell<WebAssemblyLinkErrorPrototype>(vm.heap)) WebAssemblyLinkErrorPrototype(vm, structure);
+ object->finishCreation(vm);
+ return object;
+}
+
+Structure* WebAssemblyLinkErrorPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyLinkErrorPrototype::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+}
+
+WebAssemblyLinkErrorPrototype::WebAssemblyLinkErrorPrototype(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.h b/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.h
new file mode 100644
index 000000000..aa546c2f1
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyLinkErrorPrototype.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyLinkErrorPrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyLinkErrorPrototype* create(VM&, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&);
+
+private:
+ WebAssemblyLinkErrorPrototype(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp
new file mode 100644
index 000000000..6c887af59
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.cpp
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyMemoryConstructor.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+#include "JSWebAssemblyHelpers.h"
+#include "JSWebAssemblyMemory.h"
+#include "WasmMemory.h"
+#include "WasmPageCount.h"
+#include "WebAssemblyMemoryPrototype.h"
+#include <wtf/Optional.h>
+
+#include "WebAssemblyMemoryConstructor.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyMemoryConstructor::s_info = { "Function", &Base::s_info, &constructorTableWebAssemblyMemory, CREATE_METHOD_TABLE(WebAssemblyMemoryConstructor) };
+
+/* Source for WebAssemblyMemoryConstructor.lut.h
+ @begin constructorTableWebAssemblyMemory
+ @end
+ */
+
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyMemory(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ if (exec->argumentCount() != 1)
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Memory expects exactly one argument"))));
+
+ JSObject* memoryDescriptor;
+ {
+ JSValue argument = exec->argument(0);
+ if (!argument.isObject())
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Memory expects its first argument to be an object"))));
+ memoryDescriptor = jsCast<JSObject*>(argument);
+ }
+
+ Wasm::PageCount initialPageCount;
+ {
+ Identifier initial = Identifier::fromString(&vm, "initial");
+ JSValue minSizeValue = memoryDescriptor->get(exec, initial);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ uint32_t size = toNonWrappingUint32(exec, minSizeValue);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ if (!Wasm::PageCount::isValid(size))
+ return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Memory 'initial' page count is too large"))));
+ initialPageCount = Wasm::PageCount(size);
+ }
+
+ Wasm::PageCount maximumPageCount;
+ {
+ Identifier maximum = Identifier::fromString(&vm, "maximum");
+ bool hasProperty = memoryDescriptor->hasProperty(exec, maximum);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ if (hasProperty) {
+ JSValue maxSizeValue = memoryDescriptor->get(exec, maximum);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ uint32_t size = toNonWrappingUint32(exec, maxSizeValue);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ if (!Wasm::PageCount::isValid(size))
+ return JSValue::encode(throwException(exec, throwScope, createRangeError(exec, ASCIILiteral("WebAssembly.Memory 'maximum' page count is too large"))));
+ maximumPageCount = Wasm::PageCount(size);
+
+ if (initialPageCount > maximumPageCount) {
+ return JSValue::encode(throwException(exec, throwScope,
+ createRangeError(exec, ASCIILiteral("'maximum' page count must be than greater than or equal to the 'initial' page count"))));
+ }
+ }
+ }
+
+ bool failed;
+ Wasm::Memory memory(initialPageCount, maximumPageCount, failed);
+ if (failed)
+ return JSValue::encode(throwException(exec, throwScope, createOutOfMemoryError(exec)));
+
+ return JSValue::encode(JSWebAssemblyMemory::create(vm, exec->lexicalGlobalObject()->WebAssemblyMemoryStructure(), WTFMove(memory)));
+}
+
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyMemory(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, throwScope, "WebAssembly.Memory"));
+}
+
+WebAssemblyMemoryConstructor* WebAssemblyMemoryConstructor::create(VM& vm, Structure* structure, WebAssemblyMemoryPrototype* thisPrototype)
+{
+ auto* constructor = new (NotNull, allocateCell<WebAssemblyMemoryConstructor>(vm.heap)) WebAssemblyMemoryConstructor(vm, structure);
+ constructor->finishCreation(vm, thisPrototype);
+ return constructor;
+}
+
+Structure* WebAssemblyMemoryConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyMemoryConstructor::finishCreation(VM& vm, WebAssemblyMemoryPrototype* prototype)
+{
+ Base::finishCreation(vm, ASCIILiteral("Memory"));
+ putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, DontEnum | DontDelete | ReadOnly);
+ putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
+}
+
+WebAssemblyMemoryConstructor::WebAssemblyMemoryConstructor(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+ConstructType WebAssemblyMemoryConstructor::getConstructData(JSCell*, ConstructData& constructData)
+{
+ constructData.native.function = constructJSWebAssemblyMemory;
+ return ConstructType::Host;
+}
+
+CallType WebAssemblyMemoryConstructor::getCallData(JSCell*, CallData& callData)
+{
+ callData.native.function = callJSWebAssemblyMemory;
+ return CallType::Host;
+}
+
+void WebAssemblyMemoryConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ auto* thisObject = jsCast<WebAssemblyMemoryConstructor*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
+
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.h b/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.h
new file mode 100644
index 000000000..466069335
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryConstructor.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "InternalFunction.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyMemoryPrototype;
+
+class WebAssemblyMemoryConstructor : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyMemoryConstructor* create(VM&, Structure*, WebAssemblyMemoryPrototype*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&, WebAssemblyMemoryPrototype*);
+
+private:
+ WebAssemblyMemoryConstructor(VM&, Structure*);
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
+ static void visitChildren(JSCell*, SlotVisitor&);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp
new file mode 100644
index 000000000..8d361aea6
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyMemoryPrototype.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSArrayBuffer.h"
+#include "JSCInlines.h"
+#include "JSWebAssemblyMemory.h"
+#include "JSWebAssemblyHelpers.h"
+
+namespace JSC {
+static EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState*);
+}
+
+#include "WebAssemblyMemoryPrototype.lut.h"
+
+
+namespace JSC {
+
+const ClassInfo WebAssemblyMemoryPrototype::s_info = { "WebAssembly.Memory.prototype", &Base::s_info, &prototypeTableWebAssemblyMemory, CREATE_METHOD_TABLE(WebAssemblyMemoryPrototype) };
+
+/* Source for WebAssemblyMemoryPrototype.lut.h
+@begin prototypeTableWebAssemblyMemory
+ grow webAssemblyMemoryProtoFuncGrow DontEnum|Function 1
+@end
+*/
+
+EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState*);
+
+ALWAYS_INLINE JSWebAssemblyMemory* getMemory(ExecState* exec, JSValue value)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSWebAssemblyMemory* memory = jsDynamicCast<JSWebAssemblyMemory*>(vm, value);
+ if (!memory) {
+ throwException(exec, throwScope,
+ createTypeError(exec, ASCIILiteral("WebAssembly.Memory.prototype.buffer getter called with non WebAssembly.Memory |this| value")));
+ return nullptr;
+ }
+ return memory;
+}
+
+EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncBuffer(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSWebAssemblyMemory* memory = getMemory(exec, exec->thisValue());
+ RETURN_IF_EXCEPTION(throwScope, { });
+ return JSValue::encode(memory->buffer(exec->vm(), exec->lexicalGlobalObject()));
+}
+
+EncodedJSValue JSC_HOST_CALL webAssemblyMemoryProtoFuncGrow(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSWebAssemblyMemory* memory = getMemory(exec, exec->thisValue());
+ RETURN_IF_EXCEPTION(throwScope, { });
+
+ uint32_t delta = toNonWrappingUint32(exec, exec->argument(0));
+ RETURN_IF_EXCEPTION(throwScope, { });
+
+ bool shouldThrowExceptionsOnFailure = true;
+ Wasm::PageCount result = memory->grow(exec, delta, shouldThrowExceptionsOnFailure);
+ RETURN_IF_EXCEPTION(throwScope, { });
+
+ return JSValue::encode(jsNumber(result.pageCount()));
+}
+
+WebAssemblyMemoryPrototype* WebAssemblyMemoryPrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
+{
+ auto* object = new (NotNull, allocateCell<WebAssemblyMemoryPrototype>(vm.heap)) WebAssemblyMemoryPrototype(vm, structure);
+ object->finishCreation(vm, globalObject);
+ return object;
+}
+
+Structure* WebAssemblyMemoryPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyMemoryPrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+ JSC_NATIVE_GETTER("buffer", webAssemblyMemoryProtoFuncBuffer, DontEnum | Accessor);
+}
+
+WebAssemblyMemoryPrototype::WebAssemblyMemoryPrototype(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h b/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h
new file mode 100644
index 000000000..f061fcdec
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyMemoryPrototype.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyMemoryPrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyMemoryPrototype* create(VM&, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&, JSGlobalObject*);
+
+private:
+ WebAssemblyMemoryPrototype(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp
new file mode 100644
index 000000000..81295923c
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.cpp
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyModuleConstructor.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "ExceptionHelpers.h"
+#include "FunctionPrototype.h"
+#include "JSArrayBuffer.h"
+#include "JSCInlines.h"
+#include "JSTypedArrays.h"
+#include "JSWebAssemblyCallee.h"
+#include "JSWebAssemblyCompileError.h"
+#include "JSWebAssemblyHelpers.h"
+#include "JSWebAssemblyModule.h"
+#include "SymbolTable.h"
+#include "WasmPlan.h"
+#include "WebAssemblyModulePrototype.h"
+#include <wtf/StdLibExtras.h>
+
+#include "WebAssemblyModuleConstructor.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyModuleConstructor::s_info = { "Function", &Base::s_info, &constructorTableWebAssemblyModule, CREATE_METHOD_TABLE(WebAssemblyModuleConstructor) };
+
+/* Source for WebAssemblyModuleConstructor.lut.h
+ @begin constructorTableWebAssemblyModule
+ @end
+ */
+
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyModule(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ auto* structure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), exec->lexicalGlobalObject()->WebAssemblyModuleStructure());
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ throwScope.release();
+ return JSValue::encode(WebAssemblyModuleConstructor::createModule(exec, structure));
+}
+
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyModule(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.Module"));
+}
+
+JSValue WebAssemblyModuleConstructor::createModule(ExecState* state, Structure* structure)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ size_t byteOffset;
+ size_t byteSize;
+ uint8_t* base = getWasmBufferFromValue(state, state->argument(0), byteOffset, byteSize);
+ RETURN_IF_EXCEPTION(scope, { });
+
+ Wasm::Plan plan(&vm, base + byteOffset, byteSize);
+ // On failure, a new WebAssembly.CompileError is thrown.
+ plan.run();
+ if (plan.failed())
+ return throwException(state, scope, createJSWebAssemblyCompileError(state, vm, plan.errorMessage()));
+
+ // On success, a new WebAssembly.Module object is returned with [[Module]] set to the validated Ast.module.
+
+ // The export symbol table is the same for all Instances of a Module.
+ SymbolTable* exportSymbolTable = SymbolTable::create(vm);
+ for (auto& exp : plan.exports()) {
+ auto offset = exportSymbolTable->takeNextScopeOffset(NoLockingNecessary);
+ exportSymbolTable->set(NoLockingNecessary, exp.field.impl(), SymbolTableEntry(VarOffset(offset)));
+ }
+
+ // Only wasm-internal functions have a callee, stubs to JS do not.
+ unsigned calleeCount = plan.internalFunctionCount();
+ JSWebAssemblyModule* result = JSWebAssemblyModule::create(vm, structure, plan.takeModuleInformation(), plan.takeCallLinkInfos(), plan.takeWasmExitStubs(), exportSymbolTable, calleeCount);
+ plan.initializeCallees(state->jsCallee()->globalObject(),
+ [&] (unsigned calleeIndex, JSWebAssemblyCallee* jsEntrypointCallee, JSWebAssemblyCallee* wasmEntrypointCallee) {
+ result->setJSEntrypointCallee(vm, calleeIndex, jsEntrypointCallee);
+ result->setWasmEntrypointCallee(vm, calleeIndex, wasmEntrypointCallee);
+ });
+
+ return result;
+}
+
+WebAssemblyModuleConstructor* WebAssemblyModuleConstructor::create(VM& vm, Structure* structure, WebAssemblyModulePrototype* thisPrototype)
+{
+ auto* constructor = new (NotNull, allocateCell<WebAssemblyModuleConstructor>(vm.heap)) WebAssemblyModuleConstructor(vm, structure);
+ constructor->finishCreation(vm, thisPrototype);
+ return constructor;
+}
+
+Structure* WebAssemblyModuleConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyModuleConstructor::finishCreation(VM& vm, WebAssemblyModulePrototype* prototype)
+{
+ Base::finishCreation(vm, ASCIILiteral("Module"));
+ putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, DontEnum | DontDelete | ReadOnly);
+ putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
+}
+
+WebAssemblyModuleConstructor::WebAssemblyModuleConstructor(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+ConstructType WebAssemblyModuleConstructor::getConstructData(JSCell*, ConstructData& constructData)
+{
+ constructData.native.function = constructJSWebAssemblyModule;
+ return ConstructType::Host;
+}
+
+CallType WebAssemblyModuleConstructor::getCallData(JSCell*, CallData& callData)
+{
+ callData.native.function = callJSWebAssemblyModule;
+ return CallType::Host;
+}
+
+void WebAssemblyModuleConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ auto* thisObject = jsCast<WebAssemblyModuleConstructor*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
+
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.h b/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.h
new file mode 100644
index 000000000..cf21addd1
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyModuleConstructor.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "InternalFunction.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyModulePrototype;
+
+class WebAssemblyModuleConstructor : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyModuleConstructor* create(VM&, Structure*, WebAssemblyModulePrototype*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+ static JSValue createModule(ExecState*, Structure*);
+
+protected:
+ void finishCreation(VM&, WebAssemblyModulePrototype*);
+
+private:
+ WebAssemblyModuleConstructor(VM&, Structure*);
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
+ static void visitChildren(JSCell*, SlotVisitor&);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.cpp
new file mode 100644
index 000000000..5d3c645fa
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.cpp
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyModulePrototype.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "ArrayBuffer.h"
+#include "FunctionPrototype.h"
+#include "JSArrayBuffer.h"
+#include "JSCInlines.h"
+#include "JSWebAssemblyModule.h"
+
+namespace JSC {
+static EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoCustomSections(ExecState*);
+}
+
+#include "WebAssemblyModulePrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyModulePrototype::s_info = { "WebAssembly.Module.prototype", &Base::s_info, &prototypeTableWebAssemblyModule, CREATE_METHOD_TABLE(WebAssemblyModulePrototype) };
+
+/* Source for WebAssemblyModulePrototype.lut.h
+ @begin prototypeTableWebAssemblyModule
+ customSections webAssemblyModuleProtoCustomSections DontEnum|Function 1
+ @end
+ */
+
+EncodedJSValue JSC_HOST_CALL webAssemblyModuleProtoCustomSections(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto* globalObject = exec->lexicalGlobalObject();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSWebAssemblyModule* module = jsDynamicCast<JSWebAssemblyModule*>(vm, exec->thisValue());
+ if (!module)
+ throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Module.prototype.customSections called with non WebAssembly.Module |this| value")));
+ RETURN_IF_EXCEPTION(throwScope, { });
+
+ const String sectionNameString = exec->argument(0).getString(exec);
+ RETURN_IF_EXCEPTION(throwScope, { });
+
+ JSArray* result = constructEmptyArray(exec, nullptr, globalObject);
+ RETURN_IF_EXCEPTION(throwScope, { });
+
+ const auto& customSections = module->moduleInformation().customSections;
+ for (const Wasm::CustomSection& section : customSections) {
+ if (section.name == sectionNameString) {
+ auto buffer = ArrayBuffer::tryCreate(section.payload.data(), section.payload.size());
+ if (!buffer)
+ throwException(exec, throwScope, createOutOfMemoryError(exec));
+
+ Structure* arrayBufferStructure = InternalFunction::createSubclassStructure(exec, JSValue(), globalObject->arrayBufferStructure(ArrayBufferSharingMode::Default));
+ RETURN_IF_EXCEPTION(throwScope, { });
+
+ result->push(exec, JSArrayBuffer::create(vm, arrayBufferStructure, WTFMove(buffer)));
+ RETURN_IF_EXCEPTION(throwScope, { });
+ }
+ }
+
+ return JSValue::encode(result);
+}
+
+WebAssemblyModulePrototype* WebAssemblyModulePrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
+{
+ auto* object = new (NotNull, allocateCell<WebAssemblyModulePrototype>(vm.heap)) WebAssemblyModulePrototype(vm, structure);
+ object->finishCreation(vm);
+ return object;
+}
+
+Structure* WebAssemblyModulePrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyModulePrototype::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+}
+
+WebAssemblyModulePrototype::WebAssemblyModulePrototype(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.h b/Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.h
new file mode 100644
index 000000000..d5b6279b3
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyModulePrototype.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyModulePrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyModulePrototype* create(VM&, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&);
+
+private:
+ WebAssemblyModulePrototype(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
new file mode 100644
index 000000000..f17f29df9
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
@@ -0,0 +1,291 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyModuleRecord.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "Error.h"
+#include "JSCInlines.h"
+#include "JSLexicalEnvironment.h"
+#include "JSModuleEnvironment.h"
+#include "JSWebAssemblyInstance.h"
+#include "JSWebAssemblyLinkError.h"
+#include "JSWebAssemblyModule.h"
+#include "ProtoCallFrame.h"
+#include "WasmFormat.h"
+#include "WasmSignature.h"
+#include "WebAssemblyFunction.h"
+#include <limits>
+
+namespace JSC {
+
+const ClassInfo WebAssemblyModuleRecord::s_info = { "WebAssemblyModuleRecord", &Base::s_info, nullptr, CREATE_METHOD_TABLE(WebAssemblyModuleRecord) };
+
+Structure* WebAssemblyModuleRecord::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+WebAssemblyModuleRecord* WebAssemblyModuleRecord::create(ExecState* exec, VM& vm, Structure* structure, const Identifier& moduleKey, const Wasm::ModuleInformation& moduleInformation)
+{
+ WebAssemblyModuleRecord* instance = new (NotNull, allocateCell<WebAssemblyModuleRecord>(vm.heap)) WebAssemblyModuleRecord(vm, structure, moduleKey);
+ instance->finishCreation(exec, vm, moduleInformation);
+ return instance;
+}
+
+WebAssemblyModuleRecord::WebAssemblyModuleRecord(VM& vm, Structure* structure, const Identifier& moduleKey)
+ : Base(vm, structure, moduleKey)
+{
+}
+
+void WebAssemblyModuleRecord::destroy(JSCell* cell)
+{
+ WebAssemblyModuleRecord* thisObject = static_cast<WebAssemblyModuleRecord*>(cell);
+ thisObject->WebAssemblyModuleRecord::~WebAssemblyModuleRecord();
+}
+
+void WebAssemblyModuleRecord::finishCreation(ExecState* exec, VM& vm, const Wasm::ModuleInformation& moduleInformation)
+{
+ Base::finishCreation(exec, vm);
+ ASSERT(inherits(vm, info()));
+ for (const auto& exp : moduleInformation.exports)
+ addExportEntry(ExportEntry::createLocal(exp.field, exp.field));
+}
+
+void WebAssemblyModuleRecord::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ WebAssemblyModuleRecord* thisObject = jsCast<WebAssemblyModuleRecord*>(cell);
+ Base::visitChildren(thisObject, visitor);
+ visitor.append(thisObject->m_instance);
+ visitor.append(thisObject->m_startFunction);
+}
+
+void WebAssemblyModuleRecord::link(ExecState* state, JSWebAssemblyInstance* instance)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ UNUSED_PARAM(scope);
+ auto* globalObject = state->lexicalGlobalObject();
+
+ JSWebAssemblyModule* module = instance->module();
+ const Wasm::ModuleInformation& moduleInformation = module->moduleInformation();
+
+ SymbolTable* exportSymbolTable = module->exportSymbolTable();
+ unsigned functionImportCount = module->functionImportCount();
+
+ // FIXME wire up the imports. https://bugs.webkit.org/show_bug.cgi?id=165118
+
+ // Let exports be a list of (string, JS value) pairs that is mapped from each external value e in instance.exports as follows:
+ JSModuleEnvironment* moduleEnvironment = JSModuleEnvironment::create(vm, globalObject, nullptr, exportSymbolTable, JSValue(), this);
+ for (const auto& exp : moduleInformation.exports) {
+ JSValue exportedValue;
+ switch (exp.kind) {
+ case Wasm::ExternalKind::Function: {
+ // 1. If e is a closure c:
+ // i. If there is an Exported Function Exotic Object func in funcs whose func.[[Closure]] equals c, then return func.
+ // ii. (Note: At most one wrapper is created for any closure, so func is unique, even if there are multiple occurrances in the list. Moreover, if the item was an import that is already an Exported Function Exotic Object, then the original function object will be found. For imports that are regular JS functions, a new wrapper will be created.)
+ if (exp.kindIndex < functionImportCount) {
+ // FIXME Implement re-exporting an import. https://bugs.webkit.org/show_bug.cgi?id=165510
+ RELEASE_ASSERT_NOT_REACHED();
+ }
+ // iii. Otherwise:
+ // a. Let func be an Exported Function Exotic Object created from c.
+ // b. Append func to funcs.
+ // c. Return func.
+ JSWebAssemblyCallee* jsEntrypointCallee = module->jsEntrypointCalleeFromFunctionIndexSpace(exp.kindIndex);
+ JSWebAssemblyCallee* wasmEntrypointCallee = module->wasmEntrypointCalleeFromFunctionIndexSpace(exp.kindIndex);
+ Wasm::SignatureIndex signatureIndex = module->signatureIndexFromFunctionIndexSpace(exp.kindIndex);
+ const Wasm::Signature* signature = Wasm::SignatureInformation::get(&vm, signatureIndex);
+ WebAssemblyFunction* function = WebAssemblyFunction::create(vm, globalObject, signature->argumentCount(), exp.field.string(), instance, jsEntrypointCallee, wasmEntrypointCallee, signatureIndex);
+ exportedValue = function;
+ break;
+ }
+ case Wasm::ExternalKind::Table: {
+ // This should be guaranteed by module verification.
+ RELEASE_ASSERT(instance->table());
+ ASSERT(exp.kindIndex == 0);
+
+ exportedValue = instance->table();
+ break;
+ }
+ case Wasm::ExternalKind::Memory: {
+ ASSERT(exp.kindIndex == 0);
+
+ exportedValue = instance->memory();
+ break;
+ }
+ case Wasm::ExternalKind::Global: {
+ // Assert: the global is immutable by MVP validation constraint.
+ const Wasm::Global& global = moduleInformation.globals[exp.kindIndex];
+ ASSERT(global.mutability == Wasm::Global::Immutable);
+ // Return ToJSValue(v).
+ switch (global.type) {
+ case Wasm::I32:
+ exportedValue = JSValue(instance->loadI32Global(exp.kindIndex));
+ break;
+
+ case Wasm::F32:
+ exportedValue = JSValue(instance->loadF32Global(exp.kindIndex));
+ break;
+
+ case Wasm::F64:
+ exportedValue = JSValue(instance->loadF64Global(exp.kindIndex));
+ break;
+
+ default:
+ RELEASE_ASSERT_NOT_REACHED();
+ }
+ break;
+ }
+ }
+
+ bool shouldThrowReadOnlyError = false;
+ bool ignoreReadOnlyErrors = true;
+ bool putResult = false;
+ symbolTablePutTouchWatchpointSet(moduleEnvironment, state, exp.field, exportedValue, shouldThrowReadOnlyError, ignoreReadOnlyErrors, putResult);
+ RELEASE_ASSERT(putResult);
+ }
+
+ bool hasStart = !!moduleInformation.startFunctionIndexSpace;
+ if (hasStart) {
+ auto startFunctionIndexSpace = moduleInformation.startFunctionIndexSpace.value_or(0);
+ Wasm::SignatureIndex signatureIndex = module->signatureIndexFromFunctionIndexSpace(startFunctionIndexSpace);
+ const Wasm::Signature* signature = Wasm::SignatureInformation::get(&vm, signatureIndex);
+ // The start function must not take any arguments or return anything. This is enforced by the parser.
+ ASSERT(!signature->argumentCount());
+ ASSERT(signature->returnType() == Wasm::Void);
+ if (startFunctionIndexSpace < module->functionImportCount()) {
+ JSCell* startFunction = instance->importFunction(startFunctionIndexSpace)->get();
+ m_startFunction.set(vm, this, startFunction);
+ } else {
+ JSWebAssemblyCallee* jsEntrypointCallee = module->jsEntrypointCalleeFromFunctionIndexSpace(startFunctionIndexSpace);
+ JSWebAssemblyCallee* wasmEntrypointCallee = module->wasmEntrypointCalleeFromFunctionIndexSpace(startFunctionIndexSpace);
+ WebAssemblyFunction* function = WebAssemblyFunction::create(vm, globalObject, signature->argumentCount(), "start", instance, jsEntrypointCallee, wasmEntrypointCallee, signatureIndex);
+ m_startFunction.set(vm, this, function);
+ }
+ }
+
+ RELEASE_ASSERT(!m_instance);
+ m_instance.set(vm, this, instance);
+ m_moduleEnvironment.set(vm, this, moduleEnvironment);
+}
+
+template <typename Scope, typename M, typename N, typename ...Args>
+NEVER_INLINE static JSValue dataSegmentFail(ExecState* state, VM& vm, Scope& scope, M memorySize, N segmentSize, N offset, Args... args)
+{
+ return throwException(state, scope, createJSWebAssemblyLinkError(state, vm, makeString(ASCIILiteral("Invalid data segment initialization: segment of "), String::number(segmentSize), ASCIILiteral(" bytes memory of "), String::number(memorySize), ASCIILiteral(" bytes, at offset "), String::number(offset), args...)));
+}
+
+JSValue WebAssemblyModuleRecord::evaluate(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ {
+ JSWebAssemblyModule* module = m_instance->module();
+ const Wasm::ModuleInformation& moduleInformation = module->moduleInformation();
+ JSWebAssemblyTable* table = m_instance->table();
+ for (const Wasm::Element& element : moduleInformation.elements) {
+ // It should be a validation error to have any elements without a table.
+ // Also, it could be that a table wasn't imported, or that the table
+ // imported wasn't compatible. However, those should error out before
+ // getting here.
+ ASSERT(!!table);
+ if (!element.functionIndices.size())
+ continue;
+
+ uint32_t tableIndex = element.offset;
+ uint64_t lastWrittenIndex = static_cast<uint64_t>(tableIndex) + static_cast<uint64_t>(element.functionIndices.size()) - 1;
+ if (lastWrittenIndex >= table->size())
+ return throwException(state, scope, createJSWebAssemblyLinkError(state, vm, ASCIILiteral("Element is trying to set an out of bounds table index")));
+
+ for (uint32_t i = 0; i < element.functionIndices.size(); ++i) {
+ // FIXME: This essentially means we're exporting an import.
+ // We need a story here. We need to create a WebAssemblyFunction
+ // for the import.
+ // https://bugs.webkit.org/show_bug.cgi?id=165510
+ uint32_t functionIndex = element.functionIndices[i];
+ if (functionIndex < module->functionImportCount()) {
+ return JSValue::decode(
+ throwVMRangeError(state, scope, ASCIILiteral("Element is setting the table value with an import. This is not yet implemented. FIXME.")));
+ }
+
+ JSWebAssemblyCallee* jsEntrypointCallee = module->jsEntrypointCalleeFromFunctionIndexSpace(functionIndex);
+ JSWebAssemblyCallee* wasmEntrypointCallee = module->wasmEntrypointCalleeFromFunctionIndexSpace(functionIndex);
+ Wasm::SignatureIndex signatureIndex = module->signatureIndexFromFunctionIndexSpace(functionIndex);
+ const Wasm::Signature* signature = Wasm::SignatureInformation::get(&vm, signatureIndex);
+ // FIXME: Say we export local function "foo" at funciton index 0.
+ // What if we also set it to the table an Element w/ index 0.
+ // Does (new Instance(...)).exports.foo === table.get(0)?
+ // https://bugs.webkit.org/show_bug.cgi?id=165825
+ WebAssemblyFunction* function = WebAssemblyFunction::create(
+ vm, m_instance->globalObject(), signature->argumentCount(), String(), m_instance.get(), jsEntrypointCallee, wasmEntrypointCallee, signatureIndex);
+
+ table->setFunction(vm, tableIndex, function);
+ ++tableIndex;
+ }
+ }
+ }
+
+ {
+ const Vector<Wasm::Segment::Ptr>& data = m_instance->module()->moduleInformation().data;
+ JSWebAssemblyMemory* jsMemory = m_instance->memory();
+ if (!data.isEmpty()) {
+ uint8_t* memory = reinterpret_cast<uint8_t*>(jsMemory->memory()->memory());
+ uint64_t sizeInBytes = jsMemory->memory()->size();
+ for (auto& segment : data) {
+ if (segment->sizeInBytes) {
+ uint32_t offset;
+ if (segment->offset.isGlobalImport())
+ offset = static_cast<uint32_t>(m_instance->loadI32Global(segment->offset.globalImportIndex()));
+ else
+ offset = segment->offset.constValue();
+
+ if (UNLIKELY(sizeInBytes < segment->sizeInBytes))
+ return dataSegmentFail(state, vm, scope, sizeInBytes, segment->sizeInBytes, offset, ASCIILiteral(", segment is too big"));
+ if (UNLIKELY(offset > sizeInBytes - segment->sizeInBytes))
+ return dataSegmentFail(state, vm, scope, sizeInBytes, segment->sizeInBytes, offset, ASCIILiteral(", segment writes outside of memory"));
+ RELEASE_ASSERT(memory);
+ memcpy(memory + offset, &segment->byte(0), segment->sizeInBytes);
+ }
+ }
+ }
+ }
+
+ if (JSCell* startFunction = m_startFunction.get()) {
+ CallData callData;
+ CallType callType = JSC::getCallData(startFunction, callData);
+ call(state, startFunction, callType, callData, jsUndefined(), state->emptyList());
+ RETURN_IF_EXCEPTION(scope, { });
+ }
+
+ return jsUndefined();
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h b/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h
new file mode 100644
index 000000000..e12667067
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "AbstractModuleRecord.h"
+#include "WasmFormat.h"
+
+namespace JSC {
+
+class JSWebAssemblyInstance;
+class WebAssemblyFunction;
+
+// Based on the WebAssembly.Instance specification
+// https://github.com/WebAssembly/design/blob/master/JS.md#webassemblyinstance-constructor
+class WebAssemblyModuleRecord : public AbstractModuleRecord {
+ friend class LLIntOffsetsExtractor;
+public:
+ typedef AbstractModuleRecord Base;
+
+ DECLARE_EXPORT_INFO;
+
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+ static WebAssemblyModuleRecord* create(ExecState*, VM&, Structure*, const Identifier&, const Wasm::ModuleInformation&);
+
+ void link(ExecState*, JSWebAssemblyInstance*);
+ JS_EXPORT_PRIVATE JSValue evaluate(ExecState*);
+
+private:
+ WebAssemblyModuleRecord(VM&, Structure*, const Identifier&);
+
+ void finishCreation(ExecState*, VM&, const Wasm::ModuleInformation&);
+ static void destroy(JSCell*);
+
+ static void visitChildren(JSCell*, SlotVisitor&);
+
+ WriteBarrier<JSWebAssemblyInstance> m_instance;
+ WriteBarrier<JSCell> m_startFunction;
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp
new file mode 100644
index 000000000..2d4e004ad
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.cpp
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyPrototype.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+
+namespace JSC {
+
+static EncodedJSValue JSC_HOST_CALL webAssemblyFunctionValidate(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ return JSValue::encode(throwException(state, scope, createError(state, ASCIILiteral("WebAssembly doesn't yet implement the validate function property"))));
+}
+
+static EncodedJSValue JSC_HOST_CALL webAssemblyFunctionCompile(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ return JSValue::encode(throwException(state, scope, createError(state, ASCIILiteral("WebAssembly doesn't yet implement the compile function property"))));
+}
+
+}
+
+#include "WebAssemblyPrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyPrototype::s_info = { "WebAssembly.prototype", &Base::s_info, &prototypeTableWebAssembly, CREATE_METHOD_TABLE(WebAssemblyPrototype) };
+
+/* Source for WebAssemblyPrototype.lut.h
+ @begin prototypeTableWebAssembly
+ validate webAssemblyFunctionValidate DontEnum|Function 1
+ compile webAssemblyFunctionCompile DontEnum|Function 1
+ @end
+ */
+
+WebAssemblyPrototype* WebAssemblyPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
+{
+ auto* object = new (NotNull, allocateCell<WebAssemblyPrototype>(vm.heap)) WebAssemblyPrototype(vm, structure);
+ object->finishCreation(vm);
+ return object;
+}
+
+Structure* WebAssemblyPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyPrototype::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+}
+
+WebAssemblyPrototype::WebAssemblyPrototype(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.h b/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.h
new file mode 100644
index 000000000..287d5a51b
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyPrototype.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyPrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyPrototype* create(VM&, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&);
+
+private:
+ WebAssemblyPrototype(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp
new file mode 100644
index 000000000..04aaff30a
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyRuntimeErrorConstructor.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+#include "JSWebAssemblyRuntimeError.h"
+#include "WebAssemblyRuntimeErrorPrototype.h"
+
+#include "WebAssemblyRuntimeErrorConstructor.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyRuntimeErrorConstructor::s_info = { "Function", &Base::s_info, &constructorTableWebAssemblyRuntimeError, CREATE_METHOD_TABLE(WebAssemblyRuntimeErrorConstructor) };
+
+/* Source for WebAssemblyRuntimeErrorConstructor.lut.h
+ @begin constructorTableWebAssemblyRuntimeError
+ @end
+ */
+
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyRuntimeError(ExecState* state)
+{
+ auto& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ JSValue message = state->argument(0);
+ auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyRuntimeErrorStructure());
+ RETURN_IF_EXCEPTION(scope, encodedJSValue());
+ return JSValue::encode(JSWebAssemblyRuntimeError::create(state, vm, structure, message));
+}
+
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyRuntimeError(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.RuntimeError"));
+}
+
+WebAssemblyRuntimeErrorConstructor* WebAssemblyRuntimeErrorConstructor::create(VM& vm, Structure* structure, WebAssemblyRuntimeErrorPrototype* thisPrototype)
+{
+ auto* constructor = new (NotNull, allocateCell<WebAssemblyRuntimeErrorConstructor>(vm.heap)) WebAssemblyRuntimeErrorConstructor(vm, structure);
+ constructor->finishCreation(vm, thisPrototype);
+ return constructor;
+}
+
+Structure* WebAssemblyRuntimeErrorConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyRuntimeErrorConstructor::finishCreation(VM& vm, WebAssemblyRuntimeErrorPrototype* prototype)
+{
+ Base::finishCreation(vm, ASCIILiteral("RuntimeError"));
+ putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, ReadOnly | DontEnum | DontDelete);
+ putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
+}
+
+WebAssemblyRuntimeErrorConstructor::WebAssemblyRuntimeErrorConstructor(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+ConstructType WebAssemblyRuntimeErrorConstructor::getConstructData(JSCell*, ConstructData& constructData)
+{
+ constructData.native.function = constructJSWebAssemblyRuntimeError;
+ return ConstructType::Host;
+}
+
+CallType WebAssemblyRuntimeErrorConstructor::getCallData(JSCell*, CallData& callData)
+{
+ callData.native.function = callJSWebAssemblyRuntimeError;
+ return CallType::Host;
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.h b/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.h
new file mode 100644
index 000000000..77fb6e45a
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorConstructor.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "InternalFunction.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyRuntimeErrorPrototype;
+
+class WebAssemblyRuntimeErrorConstructor : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyRuntimeErrorConstructor* create(VM&, Structure*, WebAssemblyRuntimeErrorPrototype*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&, WebAssemblyRuntimeErrorPrototype*);
+
+private:
+ WebAssemblyRuntimeErrorConstructor(VM&, Structure*);
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorPrototype.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorPrototype.cpp
new file mode 100644
index 000000000..b374dbd52
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorPrototype.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyRuntimeErrorPrototype.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+
+#include "WebAssemblyRuntimeErrorPrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyRuntimeErrorPrototype::s_info = { "WebAssembly.RuntimeError.prototype", &Base::s_info, &prototypeTableWebAssemblyRuntimeError, CREATE_METHOD_TABLE(WebAssemblyRuntimeErrorPrototype) };
+
+/* Source for WebAssemblyRuntimeErrorPrototype.lut.h
+ @begin prototypeTableWebAssemblyRuntimeError
+ @end
+ */
+
+WebAssemblyRuntimeErrorPrototype* WebAssemblyRuntimeErrorPrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
+{
+ auto* object = new (NotNull, allocateCell<WebAssemblyRuntimeErrorPrototype>(vm.heap)) WebAssemblyRuntimeErrorPrototype(vm, structure);
+ object->finishCreation(vm);
+ return object;
+}
+
+Structure* WebAssemblyRuntimeErrorPrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyRuntimeErrorPrototype::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+}
+
+WebAssemblyRuntimeErrorPrototype::WebAssemblyRuntimeErrorPrototype(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorPrototype.h b/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorPrototype.h
new file mode 100644
index 000000000..2077fa92c
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyRuntimeErrorPrototype.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyRuntimeErrorPrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyRuntimeErrorPrototype* create(VM&, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&);
+
+private:
+ WebAssemblyRuntimeErrorPrototype(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.cpp
new file mode 100644
index 000000000..12d27ab7c
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.cpp
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyTableConstructor.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+#include "JSWebAssemblyHelpers.h"
+#include "JSWebAssemblyTable.h"
+#include "WebAssemblyTablePrototype.h"
+
+#include "WebAssemblyTableConstructor.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyTableConstructor::s_info = { "Function", &Base::s_info, &constructorTableWebAssemblyTable, CREATE_METHOD_TABLE(WebAssemblyTableConstructor) };
+
+/* Source for WebAssemblyTableConstructor.lut.h
+ @begin constructorTableWebAssemblyTable
+ @end
+ */
+
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyTable(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSObject* memoryDescriptor;
+ {
+ JSValue argument = exec->argument(0);
+ if (!argument.isObject())
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table expects its first argument to be an object"))));
+ memoryDescriptor = jsCast<JSObject*>(argument);
+ }
+
+ {
+ Identifier elementIdent = Identifier::fromString(&vm, "element");
+ JSValue elementValue = memoryDescriptor->get(exec, elementIdent);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ String elementString = elementValue.toWTFString(exec);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ if (elementString != "anyfunc")
+ return JSValue::encode(throwException(exec, throwScope, createTypeError(exec, ASCIILiteral("WebAssembly.Table expects its 'element' field to be the string 'anyfunc'"))));
+ }
+
+ Identifier initialIdent = Identifier::fromString(&vm, "initial");
+ JSValue initialSizeValue = memoryDescriptor->get(exec, initialIdent);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ uint32_t initial = toNonWrappingUint32(exec, initialSizeValue);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ std::optional<uint32_t> maximum;
+ Identifier maximumIdent = Identifier::fromString(&vm, "maximum");
+ bool hasProperty = memoryDescriptor->hasProperty(exec, maximumIdent);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ if (hasProperty) {
+ JSValue maxSizeValue = memoryDescriptor->get(exec, maximumIdent);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ maximum = toNonWrappingUint32(exec, maxSizeValue);
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ if (initial > *maximum) {
+ return JSValue::encode(throwException(exec, throwScope,
+ createRangeError(exec, ASCIILiteral("'maximum' property must be greater than or equal to the 'initial' property"))));
+ }
+ }
+
+ throwScope.release();
+ return JSValue::encode(JSWebAssemblyTable::create(exec, vm, exec->lexicalGlobalObject()->WebAssemblyTableStructure(), initial, maximum));
+}
+
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyTable(ExecState* state)
+{
+ VM& vm = state->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.Table"));
+}
+
+WebAssemblyTableConstructor* WebAssemblyTableConstructor::create(VM& vm, Structure* structure, WebAssemblyTablePrototype* thisPrototype)
+{
+ auto* constructor = new (NotNull, allocateCell<WebAssemblyTableConstructor>(vm.heap)) WebAssemblyTableConstructor(vm, structure);
+ constructor->finishCreation(vm, thisPrototype);
+ return constructor;
+}
+
+Structure* WebAssemblyTableConstructor::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyTableConstructor::finishCreation(VM& vm, WebAssemblyTablePrototype* prototype)
+{
+ Base::finishCreation(vm, ASCIILiteral("Table"));
+ putDirectWithoutTransition(vm, vm.propertyNames->prototype, prototype, DontEnum | DontDelete | ReadOnly);
+ putDirectWithoutTransition(vm, vm.propertyNames->length, jsNumber(1), ReadOnly | DontEnum | DontDelete);
+}
+
+WebAssemblyTableConstructor::WebAssemblyTableConstructor(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+ConstructType WebAssemblyTableConstructor::getConstructData(JSCell*, ConstructData& constructData)
+{
+ constructData.native.function = constructJSWebAssemblyTable;
+ return ConstructType::Host;
+}
+
+CallType WebAssemblyTableConstructor::getCallData(JSCell*, CallData& callData)
+{
+ callData.native.function = callJSWebAssemblyTable;
+ return CallType::Host;
+}
+
+void WebAssemblyTableConstructor::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ auto* thisObject = jsCast<WebAssemblyTableConstructor*>(cell);
+ ASSERT_GC_OBJECT_INHERITS(thisObject, info());
+ Base::visitChildren(thisObject, visitor);
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
+
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.h b/Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.h
new file mode 100644
index 000000000..a61c7acce
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyTableConstructor.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "InternalFunction.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyTablePrototype;
+
+class WebAssemblyTableConstructor : public InternalFunction {
+public:
+ typedef InternalFunction Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyTableConstructor* create(VM&, Structure*, WebAssemblyTablePrototype*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&, WebAssemblyTablePrototype*);
+
+private:
+ WebAssemblyTableConstructor(VM&, Structure*);
+ static ConstructType getConstructData(JSCell*, ConstructData&);
+ static CallType getCallData(JSCell*, CallData&);
+ static void visitChildren(JSCell*, SlotVisitor&);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp
new file mode 100644
index 000000000..0ca8a601a
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyTablePrototype.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "FunctionPrototype.h"
+#include "JSCInlines.h"
+#include "JSWebAssemblyHelpers.h"
+#include "JSWebAssemblyTable.h"
+
+#include "WebAssemblyTablePrototype.lut.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyTablePrototype::s_info = { "WebAssembly.Table.prototype", &Base::s_info, &prototypeTableWebAssemblyTable, CREATE_METHOD_TABLE(WebAssemblyTablePrototype) };
+
+/* Source for WebAssemblyTablePrototype.lut.h
+ @begin prototypeTableWebAssemblyTable
+ @end
+ */
+
+static ALWAYS_INLINE JSWebAssemblyTable* getTable(ExecState* exec, VM& vm, JSValue v)
+{
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+ JSWebAssemblyTable* result = jsDynamicCast<JSWebAssemblyTable*>(vm, v);
+ if (!result) {
+ throwException(exec, throwScope,
+ createTypeError(exec, ASCIILiteral("expected |this| value to be an instance of WebAssembly.Table")));
+ return nullptr;
+ }
+ return result;
+}
+
+EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState*);
+EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState*);
+EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState*);
+EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState*);
+
+EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncLength(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ return JSValue::encode(jsNumber(table->size()));
+}
+
+EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGrow(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ if (!table->grow(index)) {
+ throwException(exec, throwScope,
+ createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.grow could not grow the table")));
+ return { };
+ }
+
+ return JSValue::encode(jsUndefined());
+}
+
+EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncGet(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+ if (index >= table->size()) {
+ throwException(exec, throwScope,
+ createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.get expects an integer less than the size of the table")));
+ return { };
+ }
+
+ if (WebAssemblyFunction* result = table->getFunction(index))
+ return JSValue::encode(result);
+ return JSValue::encode(jsNull());
+}
+
+EncodedJSValue JSC_HOST_CALL webAssemblyTableProtoFuncSet(ExecState* exec)
+{
+ VM& vm = exec->vm();
+ auto throwScope = DECLARE_THROW_SCOPE(vm);
+
+ JSWebAssemblyTable* table = getTable(exec, vm, exec->thisValue());
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ JSValue value = exec->argument(1);
+ WebAssemblyFunction* function = jsDynamicCast<WebAssemblyFunction*>(vm, value);
+ if (!value.isNull() && !function) {
+ throwException(exec, throwScope,
+ createTypeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects the second argument to be null or an instance of WebAssembly.Function")));
+ return { };
+ }
+
+ uint32_t index = toNonWrappingUint32(exec, exec->argument(0));
+ RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
+
+ if (index >= table->size()) {
+ throwException(exec, throwScope,
+ createRangeError(exec, ASCIILiteral("WebAssembly.Table.prototype.set expects an integer less than the size of the table")));
+ return { };
+ }
+
+ if (value.isNull())
+ table->clearFunction(index);
+ else {
+ ASSERT(!!function);
+ table->setFunction(vm, index, function);
+ }
+
+ return JSValue::encode(jsUndefined());
+}
+
+WebAssemblyTablePrototype* WebAssemblyTablePrototype::create(VM& vm, JSGlobalObject* globalObject, Structure* structure)
+{
+ auto* object = new (NotNull, allocateCell<WebAssemblyTablePrototype>(vm.heap)) WebAssemblyTablePrototype(vm, structure);
+ object->finishCreation(vm, globalObject);
+ return object;
+}
+
+Structure* WebAssemblyTablePrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
+}
+
+void WebAssemblyTablePrototype::finishCreation(VM& vm, JSGlobalObject* globalObject)
+{
+ Base::finishCreation(vm);
+
+ JSC_NATIVE_GETTER("length", webAssemblyTableProtoFuncLength, DontEnum | Accessor);
+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("grow", webAssemblyTableProtoFuncGrow, DontEnum, 1);
+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("get", webAssemblyTableProtoFuncGet, DontEnum, 1);
+ JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("set", webAssemblyTableProtoFuncSet, DontEnum, 2);
+}
+
+WebAssemblyTablePrototype::WebAssemblyTablePrototype(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h b/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h
new file mode 100644
index 000000000..5e0450578
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyTablePrototype.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSDestructibleObject.h"
+#include "JSObject.h"
+
+namespace JSC {
+
+class WebAssemblyTablePrototype : public JSNonFinalObject {
+public:
+ typedef JSNonFinalObject Base;
+ static const unsigned StructureFlags = Base::StructureFlags | HasStaticPropertyTable;
+
+ static WebAssemblyTablePrototype* create(VM&, JSGlobalObject*, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_INFO;
+
+protected:
+ void finishCreation(VM&, JSGlobalObject*);
+
+private:
+ WebAssemblyTablePrototype(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyToJSCallee.cpp b/Source/JavaScriptCore/wasm/js/WebAssemblyToJSCallee.cpp
new file mode 100644
index 000000000..4e891a09a
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyToJSCallee.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAssemblyToJSCallee.h"
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCInlines.h"
+
+namespace JSC {
+
+const ClassInfo WebAssemblyToJSCallee::s_info = { "WebAssemblyToJSCallee", nullptr, 0, CREATE_METHOD_TABLE(WebAssemblyToJSCallee) };
+
+WebAssemblyToJSCallee* WebAssemblyToJSCallee::create(VM& vm, Structure* structure)
+{
+ WebAssemblyToJSCallee* callee = new (NotNull, allocateCell<WebAssemblyToJSCallee>(vm.heap)) WebAssemblyToJSCallee(vm, structure);
+ callee->finishCreation(vm);
+ return callee;
+}
+
+Structure* WebAssemblyToJSCallee::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+{
+ return Structure::create(vm, globalObject, prototype, TypeInfo(CellType, StructureFlags), info());
+}
+
+WebAssemblyToJSCallee::WebAssemblyToJSCallee(VM& vm, Structure* structure)
+ : Base(vm, structure)
+{
+}
+
+void WebAssemblyToJSCallee::finishCreation(VM& vm)
+{
+ Base::finishCreation(vm);
+}
+
+void WebAssemblyToJSCallee::destroy(JSCell* cell)
+{
+ WebAssemblyToJSCallee* thisObject = static_cast<WebAssemblyToJSCallee*>(cell);
+ thisObject->WebAssemblyToJSCallee::~WebAssemblyToJSCallee();
+}
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)
diff --git a/Source/JavaScriptCore/wasm/js/WebAssemblyToJSCallee.h b/Source/JavaScriptCore/wasm/js/WebAssemblyToJSCallee.h
new file mode 100644
index 000000000..496c88576
--- /dev/null
+++ b/Source/JavaScriptCore/wasm/js/WebAssemblyToJSCallee.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBASSEMBLY)
+
+#include "JSCell.h"
+
+namespace JSC {
+
+class WebAssemblyToJSCallee : public JSCell {
+public:
+ typedef JSCell Base;
+ static const unsigned StructureFlags = Base::StructureFlags | StructureIsImmortal;
+
+ static WebAssemblyToJSCallee* create(VM&, Structure*);
+ static Structure* createStructure(VM&, JSGlobalObject*, JSValue);
+
+ DECLARE_EXPORT_INFO;
+ static const bool needsDestruction = true;
+ static void destroy(JSCell*);
+
+private:
+ void finishCreation(VM&);
+ WebAssemblyToJSCallee(VM&, Structure*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(WEBASSEMBLY)