зеркало из https://github.com/microsoft/napajs.git
fix and re-enable builtin type transportation (#235)
This commit is contained in:
Родитель
715b29357a
Коммит
0c621aa113
|
@ -26,6 +26,8 @@ MaybeLocal<Value> Deserializer::ReadValue() {
|
|||
return MaybeLocal<Value>();
|
||||
}
|
||||
|
||||
#if !V8_VERSION_EQUALS_TO_OR_NEWER_THAN(6, 6)
|
||||
|
||||
uint32_t index = 0;
|
||||
Local<String> key = v8_helpers::MakeV8String(_isolate, "_externalized");
|
||||
for (const auto& contents : _data->GetExternalizedSharedArrayBufferContents()) {
|
||||
|
@ -40,10 +42,38 @@ MaybeLocal<Value> Deserializer::ReadValue() {
|
|||
_deserializer.TransferSharedArrayBuffer(index++, sharedArrayBuffers);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return _deserializer.ReadValue(context);
|
||||
}
|
||||
|
||||
Deserializer* Deserializer::NewDeserializer(v8::Isolate* isolate, std::shared_ptr<SerializedData> data) {
|
||||
#if V8_VERSION_EQUALS_TO_OR_NEWER_THAN(6, 6)
|
||||
|
||||
MaybeLocal<SharedArrayBuffer> Deserializer::GetSharedArrayBufferFromId(
|
||||
Isolate* isolate, uint32_t cloneId) {
|
||||
if (_data && cloneId < _data->GetExternalizedSharedArrayBufferContents().size()) {
|
||||
auto externalizedSharedArrayBufferContents = _data->GetExternalizedSharedArrayBufferContents().at(cloneId);
|
||||
SharedArrayBuffer::Contents contents = externalizedSharedArrayBufferContents.first;
|
||||
auto sharedArrayBuffer = SharedArrayBuffer::New(isolate, contents.Data(), contents.ByteLength());
|
||||
|
||||
// After deserialization of a SharedArrayBuffer from its SerializedData,
|
||||
// set its '_externalized' property to a ShareableWrap of its ExternalizedContents.
|
||||
// This extends the lifecycle of the ExternalizedContents
|
||||
// by the lifetime of the restored SharedArrayBuffer object.
|
||||
Local<Context> context = _isolate->GetCurrentContext();
|
||||
Local<String> key = v8_helpers::MakeV8String(_isolate, "_externalized");
|
||||
auto shareableWrap = napa::module::binding::CreateShareableWrap(externalizedSharedArrayBufferContents.second);
|
||||
sharedArrayBuffer->CreateDataProperty(context, key, shareableWrap);
|
||||
return sharedArrayBuffer;
|
||||
}
|
||||
else {
|
||||
return MaybeLocal<SharedArrayBuffer>();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Deserializer* Deserializer::NewDeserializer(Isolate* isolate, std::shared_ptr<SerializedData> data) {
|
||||
return new Deserializer(isolate, data);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,15 @@ namespace v8_extensions {
|
|||
|
||||
v8::MaybeLocal<v8::Value> ReadValue();
|
||||
|
||||
static Deserializer* NewDeserializer(v8::Isolate* isolate, std::shared_ptr<SerializedData> data);
|
||||
#if V8_VERSION_EQUALS_TO_OR_NEWER_THAN(6, 6)
|
||||
|
||||
v8::MaybeLocal<v8::SharedArrayBuffer> GetSharedArrayBufferFromId(
|
||||
v8::Isolate* isolate, uint32_t cloneId) override;
|
||||
|
||||
#endif
|
||||
|
||||
static Deserializer* NewDeserializer(
|
||||
v8::Isolate* isolate, std::shared_ptr<SerializedData> data);
|
||||
|
||||
private:
|
||||
v8::Isolate* _isolate;
|
||||
|
|
|
@ -341,12 +341,11 @@ describe('napajs/transport', () => {
|
|||
|
||||
let builtinTestGroup = 'Transport built-in objects';
|
||||
let nodeVersionMajor = parseInt(process.versions.node.split('.')[0]);
|
||||
|
||||
// TODO #223: Fix transportation support for builtin types, which is broken due to breaking changes of v8 introduced from node v10.0.0.
|
||||
if (nodeVersionMajor == 9) {
|
||||
|
||||
if (nodeVersionMajor >= 9) {
|
||||
describe(builtinTestGroup, transportBuiltinObjects);
|
||||
} else {
|
||||
describe.skip(builtinTestGroup, transportBuiltinObjects);
|
||||
require('npmlog').warn(builtinTestGroup, 'This test group is skipped since it requires node v9.0.0 .');
|
||||
require('npmlog').warn(builtinTestGroup, 'This test group is skipped since it requires node v9.0.0 or above.');
|
||||
}
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче