| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#ifndef js_WasmModule_h |
| 8 |
#define js_WasmModule_h |
| 9 |
|
| 10 |
#include "mozilla/RefPtr.h" // RefPtr |
| 11 |
|
| 12 |
#include "jstypes.h" // JS_PUBLIC_API |
| 13 |
|
| 14 |
#include "js/RefCounted.h" // AtomicRefCounted |
| 15 |
#include "js/TypeDecls.h" // HandleObject |
| 16 |
|
| 17 |
namespace JS { |
| 18 |
|
| 19 |
/** |
| 20 |
* The WasmModule interface allows the embedding to hold a reference to the |
| 21 |
* underying C++ implementation of a JS WebAssembly.Module object for purposes |
| 22 |
* of efficient postMessage() and (de)serialization from a random thread. |
| 23 |
* |
| 24 |
* In particular, this allows postMessage() of a WebAssembly.Module: |
| 25 |
* GetWasmModule() is called when making a structured clone of a payload |
| 26 |
* containing a WebAssembly.Module object. The structured clone buffer holds a |
| 27 |
* refcount of the JS::WasmModule until createObject() is called in the target |
| 28 |
* agent's JSContext. The new WebAssembly.Module object continues to hold the |
| 29 |
* JS::WasmModule and thus the final reference of a JS::WasmModule may be |
| 30 |
* dropped from any thread and so the virtual destructor (and all internal |
| 31 |
* methods of the C++ module) must be thread-safe. |
| 32 |
*/ |
| 33 |
|
| 34 |
struct WasmModule : js::AtomicRefCounted<WasmModule> { |
| 35 |
virtual ~WasmModule() = default; |
| 36 |
virtual JSObject* createObject(JSContext* cx) const = 0; |
| 37 |
virtual JSObject* createObjectForAsmJS(JSContext* cx) const = 0; |
| 38 |
}; |
| 39 |
|
| 40 |
extern JS_PUBLIC_API bool IsWasmModuleObject(HandleObject obj); |
| 41 |
|
| 42 |
extern JS_PUBLIC_API RefPtr<WasmModule> GetWasmModule(HandleObject obj); |
| 43 |
|
| 44 |
} // namespace JS |
| 45 |
|
| 46 |
#endif /* js_WasmModule_h */ |