| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,7 @@ using v8::MaybeLocal; | |||
| 31 | 31 | using v8::Nothing; | |
| 32 | 32 | using v8::Object; | |
| 33 | 33 | using v8::SharedArrayBuffer; | |
| 34 | + using v8::SharedValueConveyor; | ||
| 34 | 35 | using v8::String; | |
| 35 | 36 | using v8::Symbol; | |
| 36 | 37 | using v8::Value; | |
@@ -92,10 +93,12 @@ class DeserializerDelegate : public ValueDeserializer::Delegate { | |||
| 92 | 93 | Environment* env, | |
| 93 | 94 | const std::vector<BaseObjectPtr<BaseObject>>& host_objects, | |
| 94 | 95 | const std::vector<Local<SharedArrayBuffer>>& shared_array_buffers, | |
| 95 | - const std::vector<CompiledWasmModule>& wasm_modules) | ||
| 96 | + const std::vector<CompiledWasmModule>& wasm_modules, | ||
| 97 | + const std::optional<SharedValueConveyor>& shared_value_conveyor) | ||
| 96 | 98 | : host_objects_(host_objects), | |
| 97 | 99 | shared_array_buffers_(shared_array_buffers), | |
| 98 | - wasm_modules_(wasm_modules) {} | ||
| 100 | + wasm_modules_(wasm_modules), | ||
| 101 | + shared_value_conveyor_(shared_value_conveyor) {} | ||
| 99 | 102 | ||
| 100 | 103 | MaybeLocal<Object> ReadHostObject(Isolate* isolate) override { | |
| 101 | 104 | // Identifying the index in the message's BaseObject array is sufficient. | |
@@ -128,12 +131,18 @@ class DeserializerDelegate : public ValueDeserializer::Delegate { | |||
| 128 | 131 | isolate, wasm_modules_[transfer_id]); | |
| 129 | 132 | } | |
| 130 | 133 | ||
| 134 | + const SharedValueConveyor* GetSharedValueConveyor(Isolate* isolate) override { | ||
| 135 | + CHECK(shared_value_conveyor_.has_value()); | ||
| 136 | + return &shared_value_conveyor_.value(); | ||
| 137 | + } | ||
| 138 | + | ||
| 131 | 139 | ValueDeserializer* deserializer = nullptr; | |
| 132 | 140 | ||
| 133 | 141 | private: | |
| 134 | 142 | const std::vector<BaseObjectPtr<BaseObject>>& host_objects_; | |
| 135 | 143 | const std::vector<Local<SharedArrayBuffer>>& shared_array_buffers_; | |
| 136 | 144 | const std::vector<CompiledWasmModule>& wasm_modules_; | |
| 145 | + const std::optional<SharedValueConveyor>& shared_value_conveyor_; | ||
| 137 | 146 | }; | |
| 138 | 147 | ||
| 139 | 148 | } // anonymous namespace | |
@@ -198,8 +207,12 @@ MaybeLocal<Value> Message::Deserialize(Environment* env, | |||
| 198 | 207 | shared_array_buffers.push_back(sab); | |
| 199 | 208 | } | |
| 200 | 209 | ||
| 201 | - DeserializerDelegate delegate( | ||
| 202 | - this, env, host_objects, shared_array_buffers, wasm_modules_); | ||
| 210 | + DeserializerDelegate delegate(this, | ||
| 211 | + env, | ||
| 212 | + host_objects, | ||
| 213 | + shared_array_buffers, | ||
| 214 | + wasm_modules_, | ||
| 215 | + shared_value_conveyor_); | ||
| 203 | 216 | ValueDeserializer deserializer( | |
| 204 | 217 | env->isolate(), | |
| 205 | 218 | reinterpret_cast<const uint8_t*>(main_message_buf_.data), | |
@@ -243,6 +256,10 @@ uint32_t Message::AddWASMModule(CompiledWasmModule&& mod) { | |||
| 243 | 256 | return wasm_modules_.size() - 1; | |
| 244 | 257 | } | |
| 245 | 258 | ||
| 259 | + void Message::AdoptSharedValueConveyor(SharedValueConveyor&& conveyor) { | ||
| 260 | + shared_value_conveyor_.emplace(std::move(conveyor)); | ||
| 261 | + } | ||
| 262 | + | ||
| 246 | 263 | namespace { | |
| 247 | 264 | ||
| 248 | 265 | MaybeLocal<Function> GetEmitMessageFunction(Local<Context> context) { | |
@@ -347,6 +364,12 @@ class SerializerDelegate : public ValueSerializer::Delegate { | |||
| 347 | 364 | return Just(msg_->AddWASMModule(module->GetCompiledModule())); | |
| 348 | 365 | } | |
| 349 | 366 | ||
| 367 | + bool AdoptSharedValueConveyor(Isolate* isolate, | ||
| 368 | + SharedValueConveyor&& conveyor) override { | ||
| 369 | + msg_->AdoptSharedValueConveyor(std::move(conveyor)); | ||
| 370 | + return true; | ||
| 371 | + } | ||
| 372 | + | ||
| 350 | 373 | Maybe<bool> Finish(Local<Context> context) { | |
| 351 | 374 | for (uint32_t i = 0; i < host_objects_.size(); i++) { | |
| 352 | 375 | BaseObjectPtr<BaseObject> host_object = std::move(host_objects_[i]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,6 +88,9 @@ class Message : public MemoryRetainer { | |||
| 88 | 88 | // Internal method of Message that is called when a new WebAssembly.Module | |
| 89 | 89 | // object is encountered in the incoming value's structure. | |
| 90 | 90 | uint32_t AddWASMModule(v8::CompiledWasmModule&& mod); | |
| 91 | + // Internal method of Message that is called when a shared value is | ||
| 92 | + // encountered for the first time in the incoming value's structure. | ||
| 93 | + void AdoptSharedValueConveyor(v8::SharedValueConveyor&& conveyor); | ||
| 91 | 94 | ||
| 92 | 95 | // The host objects that will be transferred, as recorded by Serialize() | |
| 93 | 96 | // (e.g. MessagePorts). | |
@@ -114,6 +117,7 @@ class Message : public MemoryRetainer { | |||
| 114 | 117 | std::vector<std::shared_ptr<v8::BackingStore>> shared_array_buffers_; | |
| 115 | 118 | std::vector<std::unique_ptr<TransferData>> transferables_; | |
| 116 | 119 | std::vector<v8::CompiledWasmModule> wasm_modules_; | |
| 120 | + std::optional<v8::SharedValueConveyor> shared_value_conveyor_; | ||
| 117 | 121 | ||
| 118 | 122 | friend class MessagePort; | |
| 119 | 123 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Flags: --harmony-struct | ||
| 4 | + | ||
| 5 | + const common = require('../common'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const { Worker, parentPort } = require('worker_threads'); | ||
| 8 | + | ||
| 9 | + // Do not use isMainThread so that this test itself can be run inside a Worker. | ||
| 10 | + if (!process.env.HAS_STARTED_WORKER) { | ||
| 11 | + process.env.HAS_STARTED_WORKER = 1; | ||
| 12 | + const m = new globalThis.SharedArray(16); | ||
| 13 | + | ||
| 14 | + const worker = new Worker(__filename); | ||
| 15 | + worker.once('message', common.mustCall((message) => { | ||
| 16 | + assert.strictEqual(message, m); | ||
| 17 | + })); | ||
| 18 | + | ||
| 19 | + worker.postMessage(m); | ||
| 20 | + } else { | ||
| 21 | + parentPort.once('message', common.mustCall((message) => { | ||
| 22 | + // Simple echo. | ||
| 23 | + parentPort.postMessage(message); | ||
| 24 | + })); | ||
| 25 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments