Skip to content

Commit f0e876f

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. [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@{nodejs#56095} PR-URL: nodejs#25331 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent cefd802 commit f0e876f

21 files changed

+444
-11
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
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

Lines changed: 41 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

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)