1/*
2 * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include "config.h"
27#include "WebAssemblyInstancePrototype.h"
28
29#if ENABLE(WEBASSEMBLY)
30
31#include "FunctionPrototype.h"
32#include "JSCInlines.h"
33#include "JSModuleNamespaceObject.h"
34#include "JSWebAssemblyInstance.h"
35
36namespace JSC {
37static EncodedJSValue JSC_HOST_CALL webAssemblyInstanceProtoFuncExports(ExecState*);
38}
39
40#include "WebAssemblyInstancePrototype.lut.h"
41
42namespace JSC {
43
44const ClassInfo WebAssemblyInstancePrototype::s_info = { "WebAssembly.Instance", &Base::s_info, &prototypeTableWebAssemblyInstance, nullptr, CREATE_METHOD_TABLE(WebAssemblyInstancePrototype) };
45
46/* Source for WebAssemblyInstancePrototype.lut.h
47 @begin prototypeTableWebAssemblyInstance
48 exports webAssemblyInstanceProtoFuncExports DontEnum|Accessor 0
49 @end
50 */
51
52static ALWAYS_INLINE JSWebAssemblyInstance* getInstance(ExecState* exec, VM& vm, JSValue v)
53{
54 auto throwScope = DECLARE_THROW_SCOPE(vm);
55 JSWebAssemblyInstance* result = jsDynamicCast<JSWebAssemblyInstance*>(vm, v);
56 if (!result) {
57 throwException(exec, throwScope,
58 createTypeError(exec, "expected |this| value to be an instance of WebAssembly.Instance"_s));
59 return nullptr;
60 }
61 return result;
62}
63
64static EncodedJSValue JSC_HOST_CALL webAssemblyInstanceProtoFuncExports(ExecState* exec)
65{
66 VM& vm = exec->vm();
67 auto throwScope = DECLARE_THROW_SCOPE(vm);
68
69 JSWebAssemblyInstance* instance = getInstance(exec, vm, exec->thisValue());
70 RETURN_IF_EXCEPTION(throwScope, { });
71 return JSValue::encode(instance->moduleNamespaceObject());
72}
73
74WebAssemblyInstancePrototype* WebAssemblyInstancePrototype::create(VM& vm, JSGlobalObject*, Structure* structure)
75{
76 auto* object = new (NotNull, allocateCell<WebAssemblyInstancePrototype>(vm.heap)) WebAssemblyInstancePrototype(vm, structure);
77 object->finishCreation(vm);
78 return object;
79}
80
81Structure* WebAssemblyInstancePrototype::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
82{
83 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
84}
85
86void WebAssemblyInstancePrototype::finishCreation(VM& vm)
87{
88 Base::finishCreation(vm);
89}
90
91WebAssemblyInstancePrototype::WebAssemblyInstancePrototype(VM& vm, Structure* structure)
92 : Base(vm, structure)
93{
94}
95
96} // namespace JSC
97
98#endif // ENABLE(WEBASSEMBLY)
99