Skip to content

Commit

Permalink
deps: cherry-pick d9fbfeb from upstream V8
Browse files Browse the repository at this point in the history
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: #25331
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
alexkozy authored and BridgeAR committed Jan 9, 2019
1 parent 7d46437 commit e1d4f43
Show file tree
Hide file tree
Showing 21 changed files with 444 additions and 11 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

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

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
41 changes: 41 additions & 0 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9950,6 +9950,47 @@ debug::TypeProfile::ScriptData debug::TypeProfile::GetScriptData(
return ScriptData(i, type_profile_);
}

v8::MaybeLocal<v8::Value> debug::WeakMap::Get(v8::Local<v8::Context> context,
v8::Local<v8::Value> key) {
PREPARE_FOR_EXECUTION(context, WeakMap, Get, Value);
auto self = Utils::OpenHandle(this);
Local<Value> result;
i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key)};
has_pending_exception =
!ToLocal<Value>(i::Execution::Call(isolate, isolate->weakmap_get(), self,
arraysize(argv), argv),
&result);
RETURN_ON_FAILED_EXECUTION(Value);
RETURN_ESCAPED(result);
}

v8::MaybeLocal<debug::WeakMap> debug::WeakMap::Set(
v8::Local<v8::Context> context, v8::Local<v8::Value> key,
v8::Local<v8::Value> value) {
PREPARE_FOR_EXECUTION(context, WeakMap, Set, WeakMap);
auto self = Utils::OpenHandle(this);
i::Handle<i::Object> result;
i::Handle<i::Object> argv[] = {Utils::OpenHandle(*key),
Utils::OpenHandle(*value)};
has_pending_exception = !i::Execution::Call(isolate, isolate->weakmap_set(),
self, arraysize(argv), argv)
.ToHandle(&result);
RETURN_ON_FAILED_EXECUTION(WeakMap);
RETURN_ESCAPED(Local<WeakMap>::Cast(Utils::ToLocal(result)));
}

Local<debug::WeakMap> debug::WeakMap::New(v8::Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
LOG_API(i_isolate, WeakMap, New);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::Handle<i::JSWeakMap> obj = i_isolate->factory()->NewJSWeakMap();
return ToApiHandle<debug::WeakMap>(obj);
}

debug::WeakMap* debug::WeakMap::Cast(v8::Value* value) {
return static_cast<debug::WeakMap*>(value);
}

const char* CpuProfileNode::GetFunctionNameStr() const {
const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this);
return node->entry()->name();
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class RegisteredExtension {
V(Proxy, JSProxy) \
V(debug::GeneratorObject, JSGeneratorObject) \
V(debug::Script, Script) \
V(debug::WeakMap, JSWeakMap) \
V(Promise, JSPromise) \
V(Primitive, Object) \
V(PrimitiveArray, FixedArray) \
Expand Down
5 changes: 3 additions & 2 deletions deps/v8/src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3435,8 +3435,9 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,

SimpleInstallFunction(isolate_, prototype, "delete",
Builtins::kWeakMapPrototypeDelete, 1, true);
SimpleInstallFunction(isolate_, prototype, "get", Builtins::kWeakMapGet, 1,
true);
Handle<JSFunction> weakmap_get = SimpleInstallFunction(
isolate_, prototype, "get", Builtins::kWeakMapGet, 1, true);
native_context()->set_weakmap_get(*weakmap_get);
SimpleInstallFunction(isolate_, prototype, "has", Builtins::kWeakMapHas, 1,
true);
Handle<JSFunction> weakmap_set = SimpleInstallFunction(
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/contexts.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ enum ContextLookupFlags {
V(WASM_RUNTIME_ERROR_FUNCTION_INDEX, JSFunction, \
wasm_runtime_error_function) \
V(WEAKMAP_SET_INDEX, JSFunction, weakmap_set) \
V(WEAKMAP_GET_INDEX, JSFunction, weakmap_get) \
V(WEAKSET_ADD_INDEX, JSFunction, weakset_add)

#define NATIVE_CONTEXT_FIELDS(V) \
Expand Down
3 changes: 3 additions & 0 deletions deps/v8/src/counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,9 @@ class RuntimeCallTimer final {
V(Map_Has) \
V(Map_New) \
V(Map_Set) \
V(WeakMap_Get) \
V(WeakMap_Set) \
V(WeakMap_New) \
V(Message_GetEndColumn) \
V(Message_GetLineNumber) \
V(Message_GetSourceLine) \
Expand Down
14 changes: 14 additions & 0 deletions deps/v8/src/debug/debug-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,20 @@ class PostponeInterruptsScope {
std::unique_ptr<i::PostponeInterruptsScope> scope_;
};

class WeakMap : public v8::Object {
public:
V8_WARN_UNUSED_RESULT v8::MaybeLocal<v8::Value> Get(
v8::Local<v8::Context> context, v8::Local<v8::Value> key);
V8_WARN_UNUSED_RESULT v8::MaybeLocal<WeakMap> Set(
v8::Local<v8::Context> context, v8::Local<v8::Value> key,
v8::Local<v8::Value> value);

static Local<WeakMap> New(v8::Isolate* isolate);
V8_INLINE static WeakMap* Cast(Value* obj);

private:
WeakMap();
};
} // namespace debug
} // namespace v8

Expand Down
26 changes: 26 additions & 0 deletions deps/v8/src/inspector/v8-debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,11 +751,37 @@ v8::MaybeLocal<v8::Value> V8Debugger::generatorScopes(
return getTargetScopes(context, generator, GENERATOR);
}

v8::MaybeLocal<v8::Uint32> V8Debugger::stableObjectId(
v8::Local<v8::Context> context, v8::Local<v8::Value> value) {
DCHECK(value->IsObject());
if (m_stableObjectId.IsEmpty()) {
m_stableObjectId.Reset(m_isolate, v8::debug::WeakMap::New(m_isolate));
}
v8::Local<v8::debug::WeakMap> stableObjectId =
m_stableObjectId.Get(m_isolate);
v8::Local<v8::Value> idValue;
if (!stableObjectId->Get(context, value).ToLocal(&idValue) ||
!idValue->IsUint32()) {
idValue = v8::Integer::NewFromUnsigned(m_isolate, ++m_lastStableObjectId);
stableObjectId->Set(context, value, idValue).ToLocalChecked();
}
return idValue.As<v8::Uint32>();
}

v8::MaybeLocal<v8::Array> V8Debugger::internalProperties(
v8::Local<v8::Context> context, v8::Local<v8::Value> value) {
v8::Local<v8::Array> properties;
if (!v8::debug::GetInternalProperties(m_isolate, value).ToLocal(&properties))
return v8::MaybeLocal<v8::Array>();
if (value->IsObject()) {
v8::Local<v8::Uint32> id;
if (stableObjectId(context, value).ToLocal(&id)) {
createDataProperty(
context, properties, properties->Length(),
toV8StringInternalized(m_isolate, "[[StableObjectId]]"));
createDataProperty(context, properties, properties->Length(), id);
}
}
if (value->IsFunction()) {
v8::Local<v8::Function> function = value.As<v8::Function>();
v8::Local<v8::Object> location;
Expand Down
6 changes: 6 additions & 0 deletions deps/v8/src/inspector/v8-debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class V8Debugger : public v8::debug::DebugDelegate,
int currentContextGroupId();
bool asyncStepOutOfFunction(int targetContextGroupId, bool onlyAtReturn);

v8::MaybeLocal<v8::Uint32> stableObjectId(v8::Local<v8::Context>,
v8::Local<v8::Value>);

v8::Isolate* m_isolate;
V8InspectorImpl* m_inspector;
int m_enableCount;
Expand Down Expand Up @@ -245,6 +248,9 @@ class V8Debugger : public v8::debug::DebugDelegate,

std::unique_ptr<TerminateExecutionCallback> m_terminateExecutionCallback;

uint32_t m_lastStableObjectId = 0;
v8::Global<v8::debug::WeakMap> m_stableObjectId;

WasmTranslation m_wasmTranslation;

DISALLOW_COPY_AND_ASSIGN(V8Debugger);
Expand Down
6 changes: 6 additions & 0 deletions deps/v8/test/inspector/debugger/eval-scopes-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Tests that variables introduced in eval scopes are accessible
{
id : <messageId>
result : {
internalProperties : [
[0] : {
name : [[StableObjectId]]
value : <StablectObjectId>
}
]
result : [
[0] : {
configurable : true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Tests that scopes do not report variables with empty names
{
id : <messageId>
result : {
internalProperties : [
[0] : {
name : [[StableObjectId]]
value : <StablectObjectId>
}
]
result : [
[0] : {
configurable : true
Expand Down
2 changes: 2 additions & 0 deletions deps/v8/test/inspector/protocol-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ InspectorTest.logMessage = function(originalMessage) {
var objects = [ message ];
while (objects.length) {
var object = objects.shift();
if (object && object.name === '[[StableObjectId]]')
object.value = '<StablectObjectId>';
for (var key in object) {
if (nonStableFields.has(key))
object[key] = `<${key}>`;
Expand Down
6 changes: 6 additions & 0 deletions deps/v8/test/inspector/runtime/es6-module-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ console.log(239)
{
id : <messageId>
result : {
internalProperties : [
[0] : {
name : [[StableObjectId]]
value : <StablectObjectId>
}
]
result : [
[0] : {
configurable : true
Expand Down
20 changes: 20 additions & 0 deletions deps/v8/test/inspector/runtime/get-properties-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Running test: testObject5
foo own string cat
Internal properties
[[PrimitiveValue]] number 5
[[StableObjectId]]: <stableObjectId>

Running test: testNotOwn
__defineGetter__ inherited function undefined
Expand All @@ -23,6 +24,8 @@ Running test: testNotOwn
toLocaleString inherited function undefined
toString inherited function undefined
valueOf inherited function undefined
Internal properties
[[StableObjectId]]: <stableObjectId>

Running test: testAccessorsOnly
b own no value, getter, setter
Expand All @@ -34,6 +37,8 @@ Running test: testArray
2 own string blue
__proto__ own object undefined
length own number 3
Internal properties
[[StableObjectId]]: <stableObjectId>

Running test: testBound
__proto__ own function undefined
Expand All @@ -42,14 +47,19 @@ Running test: testBound
Internal properties
[[BoundArgs]] object undefined
[[BoundThis]] object undefined
[[StableObjectId]]: <stableObjectId>
[[TargetFunction]] function undefined

Running test: testObjectThrowsLength
__proto__ own object undefined
length own no value, getter
Internal properties
[[StableObjectId]]: <stableObjectId>

Running test: testTypedArrayWithoutLength
__proto__ own object undefined
Internal properties
[[StableObjectId]]: <stableObjectId>

Running test: testArrayBuffer
[[Int8Array]]
Expand All @@ -62,6 +72,8 @@ Running test: testArrayBuffer
6 own number 1
7 own number 1
__proto__ own object undefined
Internal properties
[[StableObjectId]]: <stableObjectId>
[[Uint8Array]]
0 own number 1
1 own number 1
Expand All @@ -72,18 +84,26 @@ Running test: testArrayBuffer
6 own number 1
7 own number 1
__proto__ own object undefined
Internal properties
[[StableObjectId]]: <stableObjectId>
[[Int16Array]]
0 own number 257
1 own number 257
2 own number 257
3 own number 257
__proto__ own object undefined
Internal properties
[[StableObjectId]]: <stableObjectId>
[[Int32Array]]
0 own number 16843009
1 own number 16843009
__proto__ own object undefined
Internal properties
[[StableObjectId]]: <stableObjectId>

Running test: testArrayBufferWithBrokenUintCtor
[[Int8Array]] own object undefined
[[Uint8Array]] own object undefined
__proto__ own object undefined
Internal properties
[[StableObjectId]]: <stableObjectId>
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Testing regular Proxy
value : false
}
}
[3] : {
name : [[StableObjectId]]
value : <StablectObjectId>
}
]
result : [
]
Expand Down Expand Up @@ -114,6 +118,10 @@ Testing revocable Proxy
value : false
}
}
[3] : {
name : [[StableObjectId]]
value : <StablectObjectId>
}
]
result : [
]
Expand Down Expand Up @@ -166,6 +174,10 @@ Testing revocable Proxy
value : true
}
}
[3] : {
name : [[StableObjectId]]
value : <StablectObjectId>
}
]
result : [
]
Expand Down
5 changes: 4 additions & 1 deletion deps/v8/test/inspector/runtime/get-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ async function logGetPropertiesResult(objectId, flags = { ownProperties: true })
for (var i = 0; i < internalPropertyArray.length; i++) {
var p = internalPropertyArray[i];
var v = p.value;
InspectorTest.log(" " + p.name + " " + v.type + " " + v.value);
if (p.name !== '[[StableObjectId]]')
InspectorTest.log(" " + p.name + " " + v.type + " " + v.value);
else
InspectorTest.log(" [[StableObjectId]]: <stableObjectId>");
}
}

Expand Down
Loading

0 comments on commit e1d4f43

Please sign in to comment.