lib,src: use Response URL as WebAssembly location · nodejs/node@ad82694 · GitHub
Skip to content

Commit ad82694

Browse files
tniessentargos
authored andcommitted
lib,src: use Response URL as WebAssembly location
As per Section 3 of the WebAssembly Web API spec. PR-URL: #42842 Refs: #42701 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 7b70144 commit ad82694

6 files changed

Lines changed: 40 additions & 1 deletion

File tree

lib/internal/bootstrap/pre_execution.js

Lines changed: 4 additions & 0 deletions

src/node_wasm_web_api.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Local<Function> WasmStreamingObject::Initialize(Environment* env) {
2929
t->InstanceTemplate()->SetInternalFieldCount(
3030
WasmStreamingObject::kInternalFieldCount);
3131

32+
env->SetProtoMethod(t, "setURL", SetURL);
3233
env->SetProtoMethod(t, "push", Push);
3334
env->SetProtoMethod(t, "finish", Finish);
3435
env->SetProtoMethod(t, "abort", Abort);
@@ -75,6 +76,17 @@ void WasmStreamingObject::New(const FunctionCallbackInfo<Value>& args) {
7576
new WasmStreamingObject(env, args.This());
7677
}
7778

79+
void WasmStreamingObject::SetURL(const FunctionCallbackInfo<Value>& args) {
80+
WasmStreamingObject* obj;
81+
ASSIGN_OR_RETURN_UNWRAP(&obj, args.Holder());
82+
CHECK(obj->streaming_);
83+
84+
CHECK_EQ(args.Length(), 1);
85+
CHECK(args[0]->IsString());
86+
Utf8Value url(Environment::GetCurrent(args)->isolate(), args[0]);
87+
obj->streaming_->SetUrl(url.out(), url.length());
88+
}
89+
7890
void WasmStreamingObject::Push(const FunctionCallbackInfo<Value>& args) {
7991
WasmStreamingObject* obj;
8092
ASSIGN_OR_RETURN_UNWRAP(&obj, args.Holder());

src/node_wasm_web_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class WasmStreamingObject final : public BaseObject {
3333

3434
private:
3535
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
36+
static void SetURL(const v8::FunctionCallbackInfo<v8::Value>& args);
3637
static void Push(const v8::FunctionCallbackInfo<v8::Value>& args);
3738
static void Finish(const v8::FunctionCallbackInfo<v8::Value>& args);
3839
static void Abort(const v8::FunctionCallbackInfo<v8::Value>& args);

test/fixtures/crash.wasm

36 Bytes
Binary file not shown.

test/fixtures/crash.wat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(module (func (export "crash") unreachable))

test/parallel/test-wasm-web-api.js

Lines changed: 22 additions & 1 deletion

0 commit comments

Comments
 (0)