diff --git a/tooling/agent/runtime_impl.cpp b/tooling/agent/runtime_impl.cpp index 4d58d1e2cd469de533c1024437a04c882a5fcd46..e0bec028a4d9a360ea313fd5a47a145b4d6f9a38 100644 --- a/tooling/agent/runtime_impl.cpp +++ b/tooling/agent/runtime_impl.cpp @@ -199,7 +199,10 @@ DispatchResponse RuntimeImpl::GetProperties(const GetPropertiesParams ¶ms, skipProto = true; } } - if (value->IsArrayBuffer(vm_)) { + if (value->IsSendableArrayBuffer(vm_)) { + Local sendableArrayBufferRef(value); + AddSendableTypedArrayRefs(sendableArrayBufferRef, outPropertyDesc); + } else if (value->IsArrayBuffer(vm_)) { Local arrayBufferRef(value); AddTypedArrayRefs(arrayBufferRef, outPropertyDesc); } else if (value->IsSharedArrayBuffer(vm_)) { @@ -329,6 +332,56 @@ DispatchResponse RuntimeImpl::GetProperties(const GetPropertiesParams ¶ms, return DispatchResponse::Ok(); } +void RuntimeImpl::AddSendableTypedArrayRefs(Local sendableArrayBufferRef, + std::vector> *outPropertyDesc) +{ + int32_t byteLength = sendableArrayBufferRef->ByteLength(vm_); + int32_t sendableTypedArrayLength = byteLength; + AddSendableTypedArrayRef(sendableArrayBufferRef, sendableTypedArrayLength, "[[Int8Array]]", + outPropertyDesc); + AddSendableTypedArrayRef(sendableArrayBufferRef, sendableTypedArrayLength, "[[Uint8Array]]", + outPropertyDesc); + AddSendableTypedArrayRef(sendableArrayBufferRef, sendableTypedArrayLength, + "[[Uint8ClampedArray]]", outPropertyDesc); + + if ((byteLength % NumberSize::BYTES_OF_16BITS) == 0) { + sendableTypedArrayLength = byteLength / NumberSize::BYTES_OF_16BITS; + AddSendableTypedArrayRef(sendableArrayBufferRef, sendableTypedArrayLength, + "[[Int16Array]]", outPropertyDesc); + AddSendableTypedArrayRef(sendableArrayBufferRef, sendableTypedArrayLength, + "[[Uint16Array]]", outPropertyDesc); + } + + if ((byteLength % NumberSize::BYTES_OF_32BITS) == 0) { + sendableTypedArrayLength = byteLength / NumberSize::BYTES_OF_32BITS; + AddSendableTypedArrayRef(sendableArrayBufferRef, sendableTypedArrayLength, + "[[Int32Array]]", outPropertyDesc); + AddSendableTypedArrayRef(sendableArrayBufferRef, sendableTypedArrayLength, + "[[Uint32Array]]", outPropertyDesc); + AddSendableTypedArrayRef(sendableArrayBufferRef, sendableTypedArrayLength, + "[[Float32Array]]", outPropertyDesc); + } +} + +template +void RuntimeImpl::AddSendableTypedArrayRef(Local sendableArrayBufferRef, int32_t length, + const char *name, + std::vector> *outPropertyDesc) +{ + Local jsValueRef(SendableTypedArrayRef::New(vm_, sendableArrayBufferRef, 0, length)); + std::unique_ptr remoteObject = RemoteObject::FromTagged(vm_, jsValueRef); + remoteObject->SetObjectId(curObjectId_); + properties_[curObjectId_++] = Global(vm_, jsValueRef); + std::unique_ptr debuggerProperty = std::make_unique(); + debuggerProperty->SetName(name) + .SetWritable(true) + .SetConfigurable(true) + .SetEnumerable(false) + .SetIsOwn(true) + .SetValue(std::move(remoteObject)); + outPropertyDesc->emplace_back(std::move(debuggerProperty)); +} + void RuntimeImpl::AddTypedArrayRefs(Local arrayBufferRef, std::vector> *outPropertyDesc) { diff --git a/tooling/agent/runtime_impl.h b/tooling/agent/runtime_impl.h index 0c40beb6133a4ad474cb94a42e5ef8e4ca48469d..9195100e30bcbd651c1939bc26b8a388883bedbb 100644 --- a/tooling/agent/runtime_impl.h +++ b/tooling/agent/runtime_impl.h @@ -77,6 +77,11 @@ private: void CacheObjectIfNeeded(Local valRef, RemoteObject *remoteObj); + template + void AddSendableTypedArrayRef(Local sendableArrayBufferRef, int32_t length, + const char *name, std::vector> *outPropertyDesc); + void AddSendableTypedArrayRefs(Local sendableArrayBufferRef, + std::vector> *outPropertyDesc); template void AddTypedArrayRef(Local arrayBufferRef, int32_t length, const char* name, std::vector> *outPropertyDesc); diff --git a/tooling/base/pt_types.cpp b/tooling/base/pt_types.cpp index c000ff3f432e0563fa584364aac3708667a512bb..dfc1164b5ff41000949eb44ab5664ee42702b454 100644 --- a/tooling/base/pt_types.cpp +++ b/tooling/base/pt_types.cpp @@ -425,7 +425,7 @@ std::string ObjectRemoteObject::DescriptionForObject(const EcmaVM *ecmaVm, Local if (tagged->IsMapIterator(ecmaVm)) { return DescriptionForMapIterator(); } - if (tagged->IsArrayBuffer(ecmaVm)) { + if (tagged->IsArrayBuffer(ecmaVm) || tagged->IsSendableArrayBuffer(ecmaVm)) { return DescriptionForArrayBuffer(ecmaVm, Local(tagged)); } if (tagged->IsSharedArrayBuffer(ecmaVm)) { diff --git a/tooling/test/testcases/js/container.js b/tooling/test/testcases/js/container.js index 9ad75c01cb40fd78fb983fc7a367c221f748c8e5..d703c65efa79fedd8b4d44984e998fbead4e2189 100644 --- a/tooling/test/testcases/js/container.js +++ b/tooling/test/testcases/js/container.js @@ -364,6 +364,8 @@ var o = { let sendableSet0 = sendableSet.has(1) let sendableSet1 = sendableSet.has(2) let sendableSetSize = sendableSet.size; + let sendableArrayBuffer = new SendableArrayBuffer(8); + let sendableInt8Array = new SendableUint16Array(8); var nop = undefined; } diff --git a/tooling/test/testcases/js_container_test.h b/tooling/test/testcases/js_container_test.h index 9b521de45d0db5ab9e6c9fb916a3497306273f9f..467056fe6ee86dbec0960c72fb8899f0d4cf25e5 100644 --- a/tooling/test/testcases/js_container_test.h +++ b/tooling/test/testcases/js_container_test.h @@ -35,7 +35,7 @@ public: // break on start {SocketAction::RECV, "Debugger.paused", ActionRule::STRING_CONTAIN}, // set breakpoint - {SocketAction::SEND, "b " DEBUGGER_JS_DIR "container.js 368"}, + {SocketAction::SEND, "b " DEBUGGER_JS_DIR "container.js 370"}, {SocketAction::RECV, "", ActionRule::CUSTOM_RULE, MatchRule::replySuccess}, // hit breakpoint after resume first time {SocketAction::SEND, "resume"}, @@ -65,7 +65,7 @@ public: std::string breakpoint; breakpoint = hitBreakpoints->Get(0)->GetString(); if (ret != Result::SUCCESS || breakpoint.find(sourceFile_) == std::string::npos || - breakpoint.find("367") == std::string::npos) { + breakpoint.find("369") == std::string::npos) { return false; } @@ -103,6 +103,7 @@ public: std::string unserializableValue; std::string description; for (int32_t i = 0; i < innerResult->GetSize(); i++) { + std::cout << innerResult->Get(i)->Stringify() << std::endl; std::vector infos; ret = innerResult->Get(i)->GetString("name", &name); if (ret != Result::SUCCESS) { @@ -258,6 +259,8 @@ private: { "sendableSet0", { "boolean", "true", "true" } }, { "sendableSet1", { "boolean", "true", "true" } }, { "sendableSetSize", { "number", "2", "2" } }, + { "sendableArrayBuffer", { "object", "Object", "Arraybuffer(8) [Sendable]", "Arraybuffer(8) [Sendable]" } }, + {"sendableInt8Array", {"object", "Object", "SendableUint16Array [Sendable]", "SendableUint16Array [Sendable]"}}, }; };