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