| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7b70144 commit ad82694
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -245,6 +245,10 @@ function setupFetch() { | |||
| 245 | 245 | throw new ERR_WEBASSEMBLY_RESPONSE('body has already been used'); | |
| 246 | 246 | } | |
| 247 | 247 | ||
| 248 | + if (response.url) { | ||
| 249 | + streamState.setURL(response.url); | ||
| 250 | + } | ||
| 251 | + | ||
| 248 | 252 | // Pass all data from the response body to the WebAssembly compiler. | |
| 249 | 253 | for await (const chunk of response.body) { | |
| 250 | 254 | streamState.push(chunk); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ Local<Function> WasmStreamingObject::Initialize(Environment* env) { | |||
| 29 | 29 | t->InstanceTemplate()->SetInternalFieldCount( | |
| 30 | 30 | WasmStreamingObject::kInternalFieldCount); | |
| 31 | 31 | ||
| 32 | + env->SetProtoMethod(t, "setURL", SetURL); | ||
| 32 | 33 | env->SetProtoMethod(t, "push", Push); | |
| 33 | 34 | env->SetProtoMethod(t, "finish", Finish); | |
| 34 | 35 | env->SetProtoMethod(t, "abort", Abort); | |
@@ -75,6 +76,17 @@ void WasmStreamingObject::New(const FunctionCallbackInfo<Value>& args) { | |||
| 75 | 76 | new WasmStreamingObject(env, args.This()); | |
| 76 | 77 | } | |
| 77 | 78 | ||
| 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 | + | ||
| 78 | 90 | void WasmStreamingObject::Push(const FunctionCallbackInfo<Value>& args) { | |
| 79 | 91 | WasmStreamingObject* obj; | |
| 80 | 92 | ASSIGN_OR_RETURN_UNWRAP(&obj, args.Holder()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ class WasmStreamingObject final : public BaseObject { | |||
| 33 | 33 | ||
| 34 | 34 | private: | |
| 35 | 35 | static void New(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 36 | + static void SetURL(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 36 | 37 | static void Push(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 37 | 38 | static void Finish(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 38 | 39 | static void Abort(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + (module (func (export "crash") unreachable)) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,7 @@ async function testRequest(handler) { | |||
| 19 | 19 | const server = createServer((_, res) => handler(res)).unref().listen(0); | |
| 20 | 20 | await events.once(server, 'listening'); | |
| 21 | 21 | const { port } = server.address(); | |
| 22 | - return fetch(`http://127.0.0.1:${port}/`); | ||
| 22 | + return fetch(`http://127.0.0.1:${port}/foo.wasm`); | ||
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | 25 | // Runs the given function both with the promise itself and as a continuation | |
@@ -223,4 +223,25 @@ function testCompileStreamingRejectionUsingFetch(responseCallback, rejection) { | |||
| 223 | 223 | name: 'TypeError', | |
| 224 | 224 | message: /terminated/ | |
| 225 | 225 | }); | |
| 226 | + | ||
| 227 | + // Test "Developer-Facing Display Conventions" described in the WebAssembly | ||
| 228 | + // Web API specification. | ||
| 229 | + await testCompileStreaming(() => testRequest((res) => { | ||
| 230 | + // Respond with a WebAssembly module that only exports a single function, | ||
| 231 | + // which only contains an 'unreachable' instruction. | ||
| 232 | + res.setHeader('Content-Type', 'application/wasm'); | ||
| 233 | + res.end(fixtures.readSync('crash.wasm')); | ||
| 234 | + }), async (modPromise) => { | ||
| 235 | + // Call the WebAssembly function and check that the error stack contains the | ||
| 236 | + // correct "WebAssembly location" as per the specification. | ||
| 237 | + const mod = await modPromise; | ||
| 238 | + const instance = new WebAssembly.Instance(mod); | ||
| 239 | + assert.throws(() => instance.exports.crash(), (err) => { | ||
| 240 | + const stack = err.stack.split(/\n/g); | ||
| 241 | + assert.strictEqual(stack[0], 'RuntimeError: unreachable'); | ||
| 242 | + assert.match(stack[1], | ||
| 243 | + /^\s*at http:\/\/127\.0\.0\.1:\d+\/foo\.wasm:wasm-function\[0\]:0x22$/); | ||
| 244 | + return true; | ||
| 245 | + }); | ||
| 246 | + }); | ||
| 226 | 247 | })().then(common.mustCall()); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments