@@ -74,7 +74,6 @@ inline void Debug(WASI* wasi, Args&&... args) {
74
74
75
75
76
76
using v8::Array;
77
- using v8::ArrayBuffer;
78
77
using v8::BackingStore;
79
78
using v8::BigInt;
80
79
using v8::Context;
@@ -89,7 +88,7 @@ using v8::Object;
89
88
using v8::String;
90
89
using v8::Uint32;
91
90
using v8::Value;
92
-
91
+ using v8::WasmMemoryObject;
93
92
94
93
static MaybeLocal<Value> WASIException (Local<Context> context,
95
94
int errorno,
@@ -1643,25 +1642,20 @@ void WASI::SockShutdown(const FunctionCallbackInfo<Value>& args) {
1643
1642
void WASI::_SetMemory (const FunctionCallbackInfo<Value>& args) {
1644
1643
WASI* wasi;
1645
1644
CHECK_EQ (args.Length (), 1 );
1646
- CHECK (args[0 ]->IsObject ());
1645
+ if (!args[0 ]->IsWasmMemoryObject ()) {
1646
+ return node::THROW_ERR_INVALID_ARG_TYPE (
1647
+ env, " instance.exports.memory must be a WebAssembly.Memory object" );
1648
+ }
1647
1649
ASSIGN_OR_RETURN_UNWRAP (&wasi, args.This ());
1648
- wasi->memory_ .Reset (wasi->env ()->isolate (), args[0 ].As <Object >());
1650
+ wasi->memory_ .Reset (wasi->env ()->isolate (), args[0 ].As <WasmMemoryObject >());
1649
1651
}
1650
1652
1651
1653
1652
1654
uvwasi_errno_t WASI::backingStore (char ** store, size_t * byte_length) {
1653
1655
Environment* env = this ->env ();
1654
- Local<Object> memory = PersistentToLocal::Strong (this ->memory_ );
1655
- Local<Value> prop;
1656
-
1657
- if (!memory->Get (env->context (), env->buffer_string ()).ToLocal (&prop))
1658
- return UVWASI_EINVAL;
1659
-
1660
- if (!prop->IsArrayBuffer ())
1661
- return UVWASI_EINVAL;
1662
-
1663
- Local<ArrayBuffer> ab = prop.As <ArrayBuffer>();
1664
- std::shared_ptr<BackingStore> backing_store = ab->GetBackingStore ();
1656
+ Local<WasmMemoryObject> memory = PersistentToLocal::Strong (this ->memory_ );
1657
+ std::shared_ptr<BackingStore> backing_store =
1658
+ memory->Buffer ()->GetBackingStore ();
1665
1659
*byte_length = backing_store->ByteLength ();
1666
1660
*store = static_cast <char *>(backing_store->Data ());
1667
1661
CHECK_NOT_NULL (*store);
0 commit comments