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

deps/v8/test/inspector/debugger/scope-skip-variables-with-empty-name-expected.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ Tests that scopes do not report variables with empty names
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

deps/v8/test/inspector/protocol-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ InspectorTest.logMessage = function(originalMessage) {
4545
var objects = [ message ];
4646
while (objects.length) {
4747
var object = objects.shift();
48+
if (object && object.name === '[[StableObjectId]]')
49+
object.value = '<StablectObjectId>';
4850
for (var key in object) {
4951
if (nonStableFields.has(key))
5052
object[key] = `<${key}>`;

deps/v8/test/inspector/runtime/es6-module-expected.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ console.log(239)
128128
{
129129
id : <messageId>
130130
result : {
131+
internalProperties : [
132+
[0] : {
133+
name : [[StableObjectId]]
134+
value : <StablectObjectId>
135+
}
136+
]
131137
result : [
132138
[0] : {
133139
configurable : true

deps/v8/test/inspector/runtime/get-properties-expected.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Running test: testObject5
55
foo own string cat
66
Internal properties
77
[[PrimitiveValue]] number 5
8+
[[StableObjectId]]: <stableObjectId>
89

910
Running test: testNotOwn
1011
__defineGetter__ inherited function undefined
@@ -23,6 +24,8 @@ Running test: testNotOwn
2324
toLocaleString inherited function undefined
2425
toString inherited function undefined
2526
valueOf inherited function undefined
27+
Internal properties
28+
[[StableObjectId]]: <stableObjectId>
2629

2730
Running test: testAccessorsOnly
2831
b own no value, getter, setter
@@ -34,6 +37,8 @@ Running test: testArray
3437
2 own string blue
3538
__proto__ own object undefined
3639
length own number 3
40+
Internal properties
41+
[[StableObjectId]]: <stableObjectId>
3742

3843
Running test: testBound
3944
__proto__ own function undefined
@@ -42,14 +47,19 @@ Running test: testBound
4247
Internal properties
4348
[[BoundArgs]] object undefined
4449
[[BoundThis]] object undefined
50+
[[StableObjectId]]: <stableObjectId>
4551
[[TargetFunction]] function undefined
4652

4753
Running test: testObjectThrowsLength
4854
__proto__ own object undefined
4955
length own no value, getter
56+
Internal properties
57+
[[StableObjectId]]: <stableObjectId>
5058

5159
Running test: testTypedArrayWithoutLength
5260
__proto__ own object undefined
61+
Internal properties
62+
[[StableObjectId]]: <stableObjectId>
5363

5464
Running test: testArrayBuffer
5565
[[Int8Array]]
@@ -62,6 +72,8 @@ Running test: testArrayBuffer
6272
6 own number 1
6373
7 own number 1
6474
__proto__ own object undefined
75+
Internal properties
76+
[[StableObjectId]]: <stableObjectId>
6577
[[Uint8Array]]
6678
0 own number 1
6779
1 own number 1
@@ -72,18 +84,26 @@ Running test: testArrayBuffer
7284
6 own number 1
7385
7 own number 1
7486
__proto__ own object undefined
87+
Internal properties
88+
[[StableObjectId]]: <stableObjectId>
7589
[[Int16Array]]
7690
0 own number 257
7791
1 own number 257
7892
2 own number 257
7993
3 own number 257
8094
__proto__ own object undefined
95+
Internal properties
96+
[[StableObjectId]]: <stableObjectId>
8197
[[Int32Array]]
8298
0 own number 16843009
8399
1 own number 16843009
84100
__proto__ own object undefined
101+
Internal properties
102+
[[StableObjectId]]: <stableObjectId>
85103

86104
Running test: testArrayBufferWithBrokenUintCtor
87105
[[Int8Array]] own object undefined
88106
[[Uint8Array]] own object undefined
89107
__proto__ own object undefined
108+
Internal properties
109+
[[StableObjectId]]: <stableObjectId>

deps/v8/test/inspector/runtime/get-properties-on-proxy-expected.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Testing regular Proxy
5454
value : false
5555
}
5656
}
57+
[3] : {
58+
name : [[StableObjectId]]
59+
value : <StablectObjectId>
60+
}
5761
]
5862
result : [
5963
]
@@ -114,6 +118,10 @@ Testing revocable Proxy
114118
value : false
115119
}
116120
}
121+
[3] : {
122+
name : [[StableObjectId]]
123+
value : <StablectObjectId>
124+
}
117125
]
118126
result : [
119127
]
@@ -166,6 +174,10 @@ Testing revocable Proxy
166174
value : true
167175
}
168176
}
177+
[3] : {
178+
name : [[StableObjectId]]
179+
value : <StablectObjectId>
180+
}
169181
]
170182
result : [
171183
]

deps/v8/test/inspector/runtime/get-properties.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ async function logGetPropertiesResult(objectId, flags = { ownProperties: true })
9494
for (var i = 0; i < internalPropertyArray.length; i++) {
9595
var p = internalPropertyArray[i];
9696
var v = p.value;
97-
InspectorTest.log(" " + p.name + " " + v.type + " " + v.value);
97+
if (p.name !== '[[StableObjectId]]')
98+
InspectorTest.log(" " + p.name + " " + v.type + " " + v.value);
99+
else
100+
InspectorTest.log(" [[StableObjectId]]: <stableObjectId>");
98101
}
99102
}
100103

0 commit comments

Comments
 (0)