Skip to content

Commit e1d4f43

Browse files
alexkozyBridgeAR
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. R=dgozman@chromium.org,yangguo@chromium.org 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 <dgozman@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org> Cr-Commit-Position: refs/heads/master@{#56095} PR-URL: #25331 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 7d46437 commit e1d4f43

21 files changed

+444
-11
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# Reset this number to 0 on major V8 upgrades.
3232
# Increment by one for each non-official patch applied to deps/v8.
33-
'v8_embedder_string': '-node.15',
33+
'v8_embedder_string': '-node.16',
3434

3535
# Enable disassembler for `--print-code` v8 options
3636
'v8_enable_disassembler': 1,

deps/v8/src/api.cc

+41
Original file line numberDiff line numberDiff line change
@@ -9950,6 +9950,47 @@ debug::TypeProfile::ScriptData debug::TypeProfile::GetScriptData(
99509950
return ScriptData(i, type_profile_);
99519951
}
99529952

9953+
v8::MaybeLocal<v8::Value> debug::WeakMap::Get(v8::Local<v8::Context> context,
9954+
v8::Local<v8::Value> key) {
9955+
PREPARE_FOR_EXECUTION(context, WeakMap, Get, Value);
9956+
auto self = Utils::OpenHandle(this);
9957+
Local<Value> result;
9958+
i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
9959+
has_pending_exception =
9960+
!ToLocal<Value>(i::Execution::Call(isolate, isolate->weakmap_get(), self,
9961+
arraysize(argv), argv),
9962+
&result);
9963+
RETURN_ON_FAILED_EXECUTION(Value);
9964+
RETURN_ESCAPED(result);
9965+
}
9966+
9967+
v8::MaybeLocal<debug::WeakMap> debug::WeakMap::Set(
9968+
v8::Local<v8::Context> context, v8::Local<v8::Value> key,
9969+
v8::Local<v8::Value> value) {
9970+
PREPARE_FOR_EXECUTION(context, WeakMap, Set, WeakMap);
9971+
auto self = Utils::OpenHandle(this);
9972+
i::Handle<i::Object> result;
9973+
i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key),
9974+
Utils::OpenHandle(*value)};
9975+
has_pending_exception = !i::Execution::Call(isolate, isolate->weakmap_set(),
9976+
self, arraysize(argv), argv)
9977+
.ToHandle(&result);
9978+
RETURN_ON_FAILED_EXECUTION(WeakMap);
9979+
RETURN_ESCAPED(Local<WeakMap>::Cast(Utils::ToLocal(result)));
9980+
}
9981+
9982+
Local<debug::WeakMap> debug::WeakMap::New(v8::Isolate* isolate) {
9983+
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
9984+
LOG_API(i_isolate, WeakMap, New);
9985+
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
9986+
i::Handle<i::JSWeakMap> obj = i_isolate->factory()->NewJSWeakMap();
9987+
return ToApiHandle<debug::WeakMap>(obj);
9988+
}
9989+
9990+
debug::WeakMap* debug::WeakMap::Cast(v8::Value* value) {
9991+
return static_cast<debug::WeakMap*>(value);
9992+
}
9993+
99539994
const char* CpuProfileNode::GetFunctionNameStr() const {
99549995
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
99559996
return node->entry()->name();

deps/v8/src/api.h

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class RegisteredExtension {
116116
V(Proxy, JSProxy) \
117117
V(debug::GeneratorObject, JSGeneratorObject) \
118118
V(debug::Script, Script) \
119+
V(debug::WeakMap, JSWeakMap) \
119120
V(Promise, JSPromise) \
120121
V(Primitive, Object) \
121122
V(PrimitiveArray, FixedArray) \

deps/v8/src/bootstrapper.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -3435,8 +3435,9 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
34353435

34363436
SimpleInstallFunction(isolate_, prototype, "delete",
34373437
Builtins::kWeakMapPrototypeDelete, 1, true);
3438-
SimpleInstallFunction(isolate_, prototype, "get", Builtins::kWeakMapGet, 1,
3439-
true);
3438+
Handle<JSFunction> weakmap_get = SimpleInstallFunction(
3439+
isolate_, prototype, "get", Builtins::kWeakMapGet, 1, true);
3440+
native_context()->set_weakmap_get(*weakmap_get);
34403441
SimpleInstallFunction(isolate_, prototype, "has", Builtins::kWeakMapHas, 1,
34413442
true);
34423443
Handle<JSFunction> weakmap_set = SimpleInstallFunction(

deps/v8/src/contexts.h

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ enum ContextLookupFlags {
112112
V(WASM_RUNTIME_ERROR_FUNCTION_INDEX, JSFunction, \
113113
wasm_runtime_error_function) \
114114
V(WEAKMAP_SET_INDEX, JSFunction, weakmap_set) \
115+
V(WEAKMAP_GET_INDEX, JSFunction, weakmap_get) \
115116
V(WEAKSET_ADD_INDEX, JSFunction, weakset_add)
116117

117118
#define NATIVE_CONTEXT_FIELDS(V) \

deps/v8/src/counters.h

+3
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,9 @@ class RuntimeCallTimer final {
750750
V(Map_Has) \
751751
V(Map_New) \
752752
V(Map_Set) \
753+
V(WeakMap_Get) \
754+
V(WeakMap_Set) \
755+
V(WeakMap_New) \
753756
V(Message_GetEndColumn) \
754757
V(Message_GetLineNumber) \
755758
V(Message_GetSourceLine) \

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

+14
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,20 @@ class PostponeInterruptsScope {
502502
std::unique_ptr<i::PostponeInterruptsScope> scope_;
503503
};
504504

505+
class WeakMap : public v8::Object {
506+
public:
507+
V8_WARN_UNUSED_RESULT v8::MaybeLocal<v8::Value> Get(
508+
v8::Local<v8::Context> context, v8::Local<v8::Value> key);
509+
V8_WARN_UNUSED_RESULT v8::MaybeLocal<WeakMap> Set(
510+
v8::Local<v8::Context> context, v8::Local<v8::Value> key,
511+
v8::Local<v8::Value> value);
512+
513+
static Local<WeakMap> New(v8::Isolate* isolate);
514+
V8_INLINE static WeakMap* Cast(Value* obj);
515+
516+
private:
517+
WeakMap();
518+
};
505519
} // namespace debug
506520
} // namespace v8
507521

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

+26
Original file line numberDiff line numberDiff line change
@@ -751,11 +751,37 @@ v8::MaybeLocal<v8::Value> V8Debugger::generatorScopes(
751751
return getTargetScopes(context, generator, GENERATOR);
752752
}
753753

754+
v8::MaybeLocal<v8::Uint32> V8Debugger::stableObjectId(
755+
v8::Local<v8::Context> context, v8::Local<v8::Value> value) {
756+
DCHECK(value->IsObject());
757+
if (m_stableObjectId.IsEmpty()) {
758+
m_stableObjectId.Reset(m_isolate, v8::debug::WeakMap::New(m_isolate));
759+
}
760+
v8::Local<v8::debug::WeakMap> stableObjectId =
761+
m_stableObjectId.Get(m_isolate);
762+
v8::Local<v8::Value> idValue;
763+
if (!stableObjectId->Get(context, value).ToLocal(&idValue) ||
764+
!idValue->IsUint32()) {
765+
idValue = v8::Integer::NewFromUnsigned(m_isolate, ++m_lastStableObjectId);
766+
stableObjectId->Set(context, value, idValue).ToLocalChecked();
767+
}
768+
return idValue.As<v8::Uint32>();
769+
}
770+
754771
v8::MaybeLocal<v8::Array> V8Debugger::internalProperties(
755772
v8::Local<v8::Context> context, v8::Local<v8::Value> value) {
756773
v8::Local<v8::Array> properties;
757774
if (!v8::debug::GetInternalProperties(m_isolate, value).ToLocal(&properties))
758775
return v8::MaybeLocal<v8::Array>();
776+
if (value->IsObject()) {
777+
v8::Local<v8::Uint32> id;
778+
if (stableObjectId(context, value).ToLocal(&id)) {
779+
createDataProperty(
780+
context, properties, properties->Length(),
781+
toV8StringInternalized(m_isolate, "[[StableObjectId]]"));
782+
createDataProperty(context, properties, properties->Length(), id);
783+
}
784+
}
759785
if (value->IsFunction()) {
760786
v8::Local<v8::Function> function = value.As<v8::Function>();
761787
v8::Local<v8::Object> location;

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

+6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ class V8Debugger : public v8::debug::DebugDelegate,
189189
int currentContextGroupId();
190190
bool asyncStepOutOfFunction(int targetContextGroupId, bool onlyAtReturn);
191191

192+
v8::MaybeLocal<v8::Uint32> stableObjectId(v8::Local<v8::Context>,
193+
v8::Local<v8::Value>);
194+
192195
v8::Isolate* m_isolate;
193196
V8InspectorImpl* m_inspector;
194197
int m_enableCount;
@@ -245,6 +248,9 @@ class V8Debugger : public v8::debug::DebugDelegate,
245248

246249
std::unique_ptr<TerminateExecutionCallback> m_terminateExecutionCallback;
247250

251+
uint32_t m_lastStableObjectId = 0;
252+
v8::Global<v8::debug::WeakMap> m_stableObjectId;
253+
248254
WasmTranslation m_wasmTranslation;
249255

250256
DISALLOW_COPY_AND_ASSIGN(V8Debugger);

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

+6
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

+6
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

+2
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

+6
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

+20
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

+12
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

+4-1
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)