Skip to content

Commit c9a3e40

Browse files
alexkozyBethGriggs
authored andcommitted
deps: cherry-pick d9fbfeb from upstream V8
Original commit message: inspector: return [[StableObjectId]] as internal property This property might be useful for fast '===' check. [email protected],[email protected] Bug: none Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel Change-Id: Iabc3555ce1ec2c14cf0ccd40b7d964ae144e7352 Reviewed-on: https://chromium-review.googlesource.com/1226411 Reviewed-by: Dmitry Gozman <[email protected]> Reviewed-by: Yang Guo <[email protected]> Reviewed-by: Jakob Gruber <[email protected]> Commit-Queue: Aleksey Kozyatinskiy <[email protected]> Cr-Commit-Position: refs/heads/master@{#56095} PR-URL: #25330
1 parent e20e347 commit c9a3e40

21 files changed

+444
-10
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
# Reset this number to 0 on major V8 upgrades.
3535
# Increment by one for each non-official patch applied to deps/v8.
36-
'v8_embedder_string': '-node.48',
36+
'v8_embedder_string': '-node.49',
3737

3838
# Enable disassembler for `--print-code` v8 options
3939
'v8_enable_disassembler': 1,

deps/v8/src/api.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10001,6 +10001,47 @@ debug::TypeProfile::ScriptData debug::TypeProfile::GetScriptData(
1000110001
return ScriptData(i, type_profile_);
1000210002
}
1000310003

10004+
v8::MaybeLocal<v8::Value> debug::WeakMap::Get(v8::Local<v8::Context> context,
10005+
v8::Local<v8::Value> key) {
10006+
PREPARE_FOR_EXECUTION(context, WeakMap, Get, Value);
10007+
auto self = Utils::OpenHandle(this);
10008+
Local<Value> result;
10009+
i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
10010+
has_pending_exception =
10011+
!ToLocal<Value>(i::Execution::Call(isolate, isolate->weakmap_get(), self,
10012+
arraysize(argv), argv),
10013+
&result);
10014+
RETURN_ON_FAILED_EXECUTION(Value);
10015+
RETURN_ESCAPED(result);
10016+
}
10017+
10018+
v8::MaybeLocal<debug::WeakMap> debug::WeakMap::Set(
10019+
v8::Local<v8::Context> context, v8::Local<v8::Value> key,
10020+
v8::Local<v8::Value> value) {
10021+
PREPARE_FOR_EXECUTION(context, WeakMap, Set, WeakMap);
10022+
auto self = Utils::OpenHandle(this);
10023+
i::Handle<i::Object> result;
10024+
i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key),
10025+
Utils::OpenHandle(*value)};
10026+
has_pending_exception = !i::Execution::Call(isolate, isolate->weakmap_set(),
10027+
self, arraysize(argv), argv)
10028+
.ToHandle(&result);
10029+
RETURN_ON_FAILED_EXECUTION(WeakMap);
10030+
RETURN_ESCAPED(Local<WeakMap>::Cast(Utils::ToLocal(result)));
10031+
}
10032+
10033+
Local<debug::WeakMap> debug::WeakMap::New(v8::Isolate* isolate) {
10034+
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
10035+
LOG_API(i_isolate, WeakMap, New);
10036+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
10037+
i::Handle<i::JSWeakMap> obj = i_isolate->factory()->NewJSWeakMap();
10038+
return ToApiHandle<debug::WeakMap>(obj);
10039+
}
10040+
10041+
debug::WeakMap* debug::WeakMap::Cast(v8::Value* value) {
10042+
return static_cast<debug::WeakMap*>(value);
10043+
}
10044+
1000410045
const char* CpuProfileNode::GetFunctionNameStr() const {
1000510046
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
1000610047
return node->entry()->name();

deps/v8/src/api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class RegisteredExtension {
124124
V(Proxy, JSProxy) \
125125
V(debug::GeneratorObject, JSGeneratorObject) \
126126
V(debug::Script, Script) \
127+
V(debug::WeakMap, JSWeakMap) \
127128
V(Promise, JSPromise) \
128129
V(Primitive, Object) \
129130
V(PrimitiveArray, FixedArray) \

deps/v8/src/bootstrapper.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3250,7 +3250,9 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
32503250

32513251
SimpleInstallFunction(prototype, "delete",
32523252
Builtins::kWeakMapPrototypeDelete, 1, true);
3253-
SimpleInstallFunction(prototype, "get", Builtins::kWeakMapGet, 1, true);
3253+
Handle<JSFunction> weakmap_get = SimpleInstallFunction(prototype, "get",
3254+
Builtins::kWeakMapGet, 1, true);
3255+
native_context()->set_weakmap_get(*weakmap_get);
32543256
SimpleInstallFunction(prototype, "has", Builtins::kWeakMapHas, 1, true);
32553257
Handle<JSFunction> weakmap_set = SimpleInstallFunction(
32563258
prototype, "set", Builtins::kWeakMapPrototypeSet, 2, true);

deps/v8/src/contexts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ enum ContextLookupFlags {
108108
V(WASM_RUNTIME_ERROR_FUNCTION_INDEX, JSFunction, \
109109
wasm_runtime_error_function) \
110110
V(WEAKMAP_SET_INDEX, JSFunction, weakmap_set) \
111+
V(WEAKMAP_GET_INDEX, JSFunction, weakmap_get) \
111112
V(WEAKSET_ADD_INDEX, JSFunction, weakset_add)
112113

113114
#define NATIVE_CONTEXT_FIELDS(V) \

deps/v8/src/counters.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,9 @@ class RuntimeCallTimer final {
730730
V(Map_Has) \
731731
V(Map_New) \
732732
V(Map_Set) \
733+
V(WeakMap_Get) \
734+
V(WeakMap_Set) \
735+
V(WeakMap_New) \
733736
V(Message_GetEndColumn) \
734737
V(Message_GetLineNumber) \
735738
V(Message_GetSourceLine) \

deps/v8/src/debug/debug-interface.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,20 @@ bool SetFunctionBreakpoint(v8::Local<v8::Function> function,
515515

516516
v8::Platform* GetCurrentPlatform();
517517

518+
class WeakMap : public v8::Object {
519+
public:
520+
V8_WARN_UNUSED_RESULT v8::MaybeLocal<v8::Value> Get(
521+
v8::Local<v8::Context> context, v8::Local<v8::Value> key);
522+
V8_WARN_UNUSED_RESULT v8::MaybeLocal<WeakMap> Set(
523+
v8::Local<v8::Context> context, v8::Local<v8::Value> key,
524+
v8::Local<v8::Value> value);
525+
526+
static Local<WeakMap> New(v8::Isolate* isolate);
527+
V8_INLINE static WeakMap* Cast(Value* obj);
528+
529+
private:
530+
WeakMap();
531+
};
518532
} // namespace debug
519533
} // namespace v8
520534

deps/v8/src/inspector/v8-debugger.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,11 +703,37 @@ v8::MaybeLocal<v8::Value> V8Debugger::generatorScopes(
703703
return getTargetScopes(context, generator, GENERATOR);
704704
}
705705

706+
v8::MaybeLocal<v8::Uint32> V8Debugger::stableObjectId(
707+
v8::Local<v8::Context> context, v8::Local<v8::Value> value) {
708+
DCHECK(value->IsObject());
709+
if (m_stableObjectId.IsEmpty()) {
710+
m_stableObjectId.Reset(m_isolate, v8::debug::WeakMap::New(m_isolate));
711+
}
712+
v8::Local<v8::debug::WeakMap> stableObjectId =
713+
m_stableObjectId.Get(m_isolate);
714+
v8::Local<v8::Value> idValue;
715+
if (!stableObjectId->Get(context, value).ToLocal(&idValue) ||
716+
!idValue->IsUint32()) {
717+
idValue = v8::Integer::NewFromUnsigned(m_isolate, ++m_lastStableObjectId);
718+
stableObjectId->Set(context, value, idValue).ToLocalChecked();
719+
}
720+
return idValue.As<v8::Uint32>();
721+
}
722+
706723
v8::MaybeLocal<v8::Array> V8Debugger::internalProperties(
707724
v8::Local<v8::Context> context, v8::Local<v8::Value> value) {
708725
v8::Local<v8::Array> properties;
709726
if (!v8::debug::GetInternalProperties(m_isolate, value).ToLocal(&properties))
710727
return v8::MaybeLocal<v8::Array>();
728+
if (value->IsObject()) {
729+
v8::Local<v8::Uint32> id;
730+
if (stableObjectId(context, value).ToLocal(&id)) {
731+
createDataProperty(
732+
context, properties, properties->Length(),
733+
toV8StringInternalized(m_isolate, "[[StableObjectId]]"));
734+
createDataProperty(context, properties, properties->Length(), id);
735+
}
736+
}
711737
if (value->IsFunction()) {
712738
v8::Local<v8::Function> function = value.As<v8::Function>();
713739
v8::Local<v8::Object> location;

deps/v8/src/inspector/v8-debugger.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ class V8Debugger : public v8::debug::DebugDelegate {
185185

186186
int currentContextGroupId();
187187

188+
v8::MaybeLocal<v8::Uint32> stableObjectId(v8::Local<v8::Context>,
189+
v8::Local<v8::Value>);
190+
188191
v8::Isolate* m_isolate;
189192
V8InspectorImpl* m_inspector;
190193
int m_enableCount;
@@ -241,6 +244,9 @@ class V8Debugger : public v8::debug::DebugDelegate {
241244

242245
std::unique_ptr<TerminateExecutionCallback> m_terminateExecutionCallback;
243246

247+
uint32_t m_lastStableObjectId = 0;
248+
v8::Global<v8::debug::WeakMap> m_stableObjectId;
249+
244250
WasmTranslation m_wasmTranslation;
245251

246252
DISALLOW_COPY_AND_ASSIGN(V8Debugger);

deps/v8/test/inspector/debugger/eval-scopes-expected.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Tests that variables introduced in eval scopes are accessible
22
{
33
id : <messageId>
44
result : {
5+
internalProperties : [
6+
[0] : {
7+
name : [[StableObjectId]]
8+
value : <StablectObjectId>
9+
}
10+
]
511
result : [
612
[0] : {
713
configurable : true

0 commit comments

Comments
 (0)