v8/test/inspector/runtime/stable-object-id.js
Alexey Kozyatinskiy d9fbfeb894 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}
2018-09-20 15:03:52 +00:00

88 lines
3.6 KiB
JavaScript

// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} = InspectorTest.start(
'Checks that protocol returns the same RemoteObjectId for the same object');
InspectorTest.runAsyncTestSuite([
async function testGlobal() {
const {result:{result:{objectId:firstId}}} =
await Protocol.Runtime.evaluate({expression: 'this'});
const firstStableId = await stableObjectId(firstId);
const {result:{result:{objectId:secondId}}} =
await Protocol.Runtime.evaluate({expression: 'this'});
const secondStableId = await stableObjectId(secondId);
InspectorTest.log(
`Compare global evaluated twice: ${firstStableId === secondStableId}`);
},
async function testObject() {
const {result:{result:{objectId:firstId}}} =
await Protocol.Runtime.evaluate({expression: 'this.a = {}, this.a'});
const firstStableId = await stableObjectId(firstId);
const {result:{result:{objectId:secondId}}} =
await Protocol.Runtime.evaluate({expression: 'this.a'});
const secondStableId = await stableObjectId(secondId);
InspectorTest.log(
`Compare object evaluated twice: ${firstStableId === secondStableId}`);
},
async function testObjectInArray() {
await Protocol.Runtime.evaluate({expression: 'this.b = [this.a, this.a]'});
const {result:{result:{objectId:firstId}}} =
await Protocol.Runtime.evaluate({expression: 'this.b[0]'});
const firstStableId = await stableObjectId(firstId);
const {result:{result:{objectId:secondId}}} =
await Protocol.Runtime.evaluate({expression: 'this.b[1]'});
const secondStableId = await stableObjectId(secondId);
InspectorTest.log(
`Compare first and second element: ${firstStableId === secondStableId}`);
},
async function testObjectOnPause() {
const {result:{result:{objectId:globalId}}} =
await Protocol.Runtime.evaluate({expression: 'this'});
const globalStableId = await stableObjectId(globalId);
const {result:{result:{objectId:aId}}} =
await Protocol.Runtime.evaluate({expression: 'this.a'});
const aStableId = await stableObjectId(aId);
await Protocol.Debugger.enable();
Protocol.Runtime.evaluate({expression: 'debugger'});
const {params:{callFrames:[topFrame]}} =
await Protocol.Debugger.oncePaused();
const topFrameThisStableId = await stableObjectId(topFrame.this.objectId);
InspectorTest.log(
`Compare global and this: ${globalStableId === topFrameThisStableId}`);
const {result:{result:{objectId:globalIdOnPause}}} =
await Protocol.Debugger.evaluateOnCallFrame({
callFrameId: topFrame.callFrameId,
expression: 'this'
});
const globalStableIdOnPause = await stableObjectId(globalIdOnPause);
InspectorTest.log(
`Compare global and global on pause: ${
globalStableId === globalStableIdOnPause}`);
const {result:{result: props}} = await Protocol.Runtime.getProperties({
objectId: topFrame.scopeChain[0].object.objectId
});
const {value:{objectId: aIdOnPause}} = props.find(prop => prop.name === 'a');
const aStableIdOnPause = await stableObjectId(aIdOnPause);
InspectorTest.log(`Compare a and a on pause: ${
aStableId === aStableIdOnPause}`);
}
]);
async function stableObjectId(objectId) {
const {result:{
internalProperties: props
}} = await Protocol.Runtime.getProperties({
objectId,
ownProperties: true,
generatePreview: false
});
return props.find(prop => prop.name === '[[StableObjectId]]').value.value;
}