Commit 3a20c322 authored by luoe's avatar luoe Committed by Commit bot

[inspector] remove iterators and for...of loops from injected-script-source

BUG=chromium:686003

Review-Url: https://codereview.chromium.org/2705533002
Cr-Commit-Position: refs/heads/master@{#43595}
parent 9ef1e35b
This diff is collapsed.
......@@ -162,6 +162,20 @@ void InspectorClientImpl::disconnect() {
session_.reset();
}
bool InspectorClientImpl::formatAccessorsAsProperties(
v8::Local<v8::Value> object) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Local<v8::Private> shouldFormatAccessorsPrivate = v8::Private::ForApi(
isolate, v8::String::NewFromUtf8(isolate, "allowAccessorFormatting",
v8::NewStringType::kNormal)
.ToLocalChecked());
CHECK(object->IsObject());
return object.As<v8::Object>()
->HasPrivate(context, shouldFormatAccessorsPrivate)
.FromMaybe(false);
}
v8::Local<v8::Context> InspectorClientImpl::ensureDefaultContextInGroup(int) {
CHECK(isolate_);
return context_.Get(isolate_);
......
......@@ -38,6 +38,7 @@ class InspectorClientImpl : public v8_inspector::V8InspectorClient {
private:
// V8InspectorClient implementation.
bool formatAccessorsAsProperties(v8::Local<v8::Value>) override;
v8::Local<v8::Context> ensureDefaultContextInGroup(
int context_group_id) override;
double currentTimeMS() override;
......
......@@ -382,7 +382,8 @@ class InspectorExtension : public v8::Extension {
"native function setMaxAsyncTaskStacks();"
"native function breakProgram();"
"native function createObjectWithStrictCheck();"
"native function callWithScheduledBreak();") {}
"native function callWithScheduledBreak();"
"native function allowAccessorFormatting();") {}
virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) {
......@@ -427,6 +428,13 @@ class InspectorExtension : public v8::Extension {
.FromJust()) {
return v8::FunctionTemplate::New(
isolate, InspectorExtension::CallWithScheduledBreak);
} else if (name->Equals(context, v8::String::NewFromUtf8(
isolate, "allowAccessorFormatting",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
return v8::FunctionTemplate::New(
isolate, InspectorExtension::AllowAccessorFormatting);
}
return v8::Local<v8::FunctionTemplate>();
}
......@@ -525,6 +533,24 @@ class InspectorExtension : public v8::Extension {
nullptr);
session->cancelPauseOnNextStatement();
}
static void AllowAccessorFormatting(
const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1 || !args[0]->IsObject()) {
fprintf(stderr, "Internal error: allowAccessorFormatting('object').");
Exit();
}
v8::Local<v8::Object> object = args[0].As<v8::Object>();
v8::Isolate* isolate = args.GetIsolate();
v8::Local<v8::Private> shouldFormatAccessorsPrivate = v8::Private::ForApi(
isolate, v8::String::NewFromUtf8(isolate, "allowAccessorFormatting",
v8::NewStringType::kNormal)
.ToLocalChecked());
object
->SetPrivate(isolate->GetCurrentContext(), shouldFormatAccessorsPrivate,
v8::Null(isolate))
.ToChecked();
}
};
v8::Local<v8::String> ToString(v8::Isolate* isolate,
......
......@@ -43,6 +43,26 @@ var inheritingObj = {};
var inheritingArr = [];
inheritingObj.prototype = obj;
inheritingArr.prototype = arr;
var shortTypedArray = new Uint8Array(3);
var longTypedArray = new Uint8Array(500001);
var set = new Set([1, 2, 3]);
var bigSet = new Set();
var mixedSet = new Set();
for (var i = 0; i < 10; i++) {
bigSet.add(i);
mixedSet["_prop_" + i] = 1;
mixedSet.add(i);
}
var deterministicNativeFunction = Math.log;
var parentObj = {};
Object.defineProperty(parentObj, 'propNotNamedProto', {
get: deterministicNativeFunction,
set: function() {}
});
var objInheritsGetterProperty = {__proto__: parentObj};
allowAccessorFormatting(objInheritsGetterProperty);
`);
InspectorTest.runTestSuite([
......@@ -72,5 +92,47 @@ InspectorTest.runTestSuite([
Protocol.Runtime.evaluate({ "expression": "inheritingArr", "generatePreview": true })
.then(result => InspectorTest.logMessage(result.result.result.preview))
.then(next);
},
function testShortTypedArrayPropertiesPreview(next)
{
Protocol.Runtime.evaluate({ "expression": "shortTypedArray", "generatePreview": true })
.then(result => InspectorTest.logMessage(result.result.result.preview))
.then(next);
},
function testLongTypedArrayPropertiesPreview(next)
{
Protocol.Runtime.evaluate({ "expression": "longTypedArray", "generatePreview": true })
.then(result => InspectorTest.logMessage(result.result.result.preview))
.then(next);
},
function testSetPropertiesPreview(next)
{
Protocol.Runtime.evaluate({ "expression": "set", "generatePreview": true })
.then(result => InspectorTest.logMessage(result.result.result.preview))
.then(next);
},
function testBigSetPropertiesPreview(next)
{
Protocol.Runtime.evaluate({ "expression": "bigSet", "generatePreview": true })
.then(result => InspectorTest.logMessage(result.result.result.preview))
.then(next);
},
function testMixedSetPropertiesPreview(next)
{
Protocol.Runtime.evaluate({ "expression": "mixedSet", "generatePreview": true })
.then(result => InspectorTest.logMessage(result.result.result.preview))
.then(next);
},
function testObjInheritsGetterProperty(next)
{
Protocol.Runtime.evaluate({ "expression": "objInheritsGetterProperty", "generatePreview": true })
.then(result => InspectorTest.logMessage(result.result.result.preview))
.then(next);
}
]);
......@@ -37,3 +37,8 @@ Internal properties
[[BoundArgs]] object undefined
[[BoundThis]] object undefined
[[TargetFunction]] function undefined
Properties of Object that throws on length access
__proto__ own object undefined
length own no value, getter
Properties of TypedArray without length
__proto__ own object undefined
......@@ -176,6 +176,46 @@ function callbackEvalBound(result)
function callbackPropertiesBound(result)
{
logGetPropertiesResult("Bound function", result);
return { callback: callbackStartObjectThrowsLength };
}
// Object throws on length access
function callbackStartObjectThrowsLength() {
var expression = "({get length() { throw 'Length called'; }})";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalObjectThrowsLength };
}
function callbackEvalObjectThrowsLength(result) {
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackPropertiesObjectThrowsLength
};
}
function callbackPropertiesObjectThrowsLength(result) {
logGetPropertiesResult("Object that throws on length access", result);
return { callback: callbackStartTypedArrayWithoutLength };
}
// Typed array without length
function callbackStartTypedArrayWithoutLength() {
var expression = "({__proto__: Uint8Array.prototype})";
return { command: "Runtime.evaluate", params: {expression: expression}, callback: callbackEvalTypedArrayWithoutLength };
}
function callbackEvalTypedArrayWithoutLength(result) {
var id = result.result.objectId;
if (id === undefined)
throw new Error("objectId is expected");
return {
command: "Runtime.getProperties", params: {objectId: id, ownProperties: true}, callback: callbackPropertiesTypedArrayWithoutLength
};
}
function callbackPropertiesTypedArrayWithoutLength(result) {
logGetPropertiesResult("TypedArray without length", result);
return; // End of test
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment