Commit 66d5519f authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

Revert of Correctly compute line numbers in functions from the function...

Revert of Correctly compute line numbers in functions from the function constructor. (patchset #5 id:80001 of https://codereview.chromium.org/701093003/)

Reason for revert:
Locations from New Function are broken in DevTools.

Original issue's description:
> Correctly compute line numbers in functions from the function constructor.
>
> R=aandrey@chromium.org
> BUG=chromium:109362
> LOG=Y
>
> Committed: https://code.google.com/p/v8/source/detail?r=25289

TBR=aandrey@chromium.org,yangguo@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=chromium:109362
LOG=Y

Review URL: https://codereview.chromium.org/1053563002

Cr-Commit-Position: refs/heads/master@{#27564}
parent ef7e6fb1
......@@ -277,8 +277,8 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, Code* code,
int position = static_cast<int>(it.rinfo()->data());
if (position >= 0) {
int pc_offset = static_cast<int>(it.rinfo()->pc() - code->address());
int line_number = script->GetLineNumber(position);
line_table->SetPosition(pc_offset, line_number + 1);
int line_number = script->GetLineNumber(position) + 1;
line_table->SetPosition(pc_offset, line_number);
}
}
}
......
......@@ -74,7 +74,13 @@ function GeneratorFunctionPrototypeConstructor(x) {
}
function GeneratorFunctionConstructor(arg1) { // length == 1
return NewFunctionFromString(arguments, 'function*');
var source = NewFunctionString(arguments, 'function*');
var global_proxy = %GlobalProxy(global);
// Compile the string in the constructor and not a helper so that errors
// appear to come from here.
var f = %_CallFunction(global_proxy, %CompileString(source, true));
%FunctionMarkNameShouldPrintAsAnonymous(f);
return f;
}
......
......@@ -410,26 +410,34 @@ function MakeReferenceErrorEmbedded(type, arg) {
else the line number.
*/
function ScriptLineFromPosition(position) {
var lower = 0;
var upper = this.lineCount() - 1;
var line_ends = this.line_ends;
var upper = line_ends.length - 1;
if (upper < 0) return -1;
// We'll never find invalid positions so bail right away.
if (position > line_ends[upper]) return -1;
if (position <= line_ends[0]) return 0;
var lower = 1;
// Binary search.
while (true) {
var mid = (upper + lower) >> 1;
if (position <= line_ends[mid - 1]) {
upper = mid - 1;
} else if (position > line_ends[mid]){
lower = mid + 1;
if (position > line_ends[upper]) {
return -1;
}
// This means we don't have to safe-guard indexing line_ends[i - 1].
if (position <= line_ends[0]) {
return 0;
}
// Binary search to find line # from position range.
while (upper >= 1) {
var i = (lower + upper) >> 1;
if (position > line_ends[i]) {
lower = i + 1;
} else if (position <= line_ends[i - 1]) {
upper = i - 1;
} else {
return mid;
return i;
}
}
return -1;
}
/**
......
......@@ -10367,31 +10367,27 @@ int Script::GetColumnNumber(Handle<Script> script, int code_pos) {
}
int Script::GetLineNumberWithArray(int position) {
int Script::GetLineNumberWithArray(int code_pos) {
DisallowHeapAllocation no_allocation;
FixedArray* line_ends = FixedArray::cast(this->line_ends());
int upper = line_ends->length() - 1;
if (upper < 0) return -1;
int offset = line_offset()->value();
DCHECK(line_ends()->IsFixedArray());
FixedArray* line_ends_array = FixedArray::cast(line_ends());
int line_ends_len = line_ends_array->length();
if (line_ends_len == 0) return -1;
if (position > Smi::cast(line_ends->get(upper))->value()) {
return upper + 1 + offset;
if ((Smi::cast(line_ends_array->get(0)))->value() >= code_pos) {
return line_offset()->value();
}
if (position <= Smi::cast(line_ends->get(0))->value()) return offset;
int lower = 1;
// Binary search.
while (true) {
int mid = (lower + upper) / 2;
if (position <= Smi::cast(line_ends->get(mid - 1))->value()) {
upper = mid - 1;
} else if (position > Smi::cast(line_ends->get(mid))->value()) {
lower = mid + 1;
int left = 0;
int right = line_ends_len;
while (int half = (right - left) / 2) {
if ((Smi::cast(line_ends_array->get(left + half)))->value() > code_pos) {
right -= half;
} else {
return mid + offset;
left += half;
}
}
return -1;
return right + line_offset()->value();
}
......
......@@ -349,10 +349,9 @@ bool CodeGenerationFromStringsAllowed(Isolate* isolate,
RUNTIME_FUNCTION(Runtime_CompileString) {
HandleScope scope(isolate);
DCHECK(args.length() == 3);
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1);
CONVERT_SMI_ARG_CHECKED(source_offset, 2);
// Extract native context.
Handle<Context> context(isolate->native_context());
......@@ -378,14 +377,6 @@ RUNTIME_FUNCTION(Runtime_CompileString) {
isolate, fun,
Compiler::GetFunctionFromEval(source, outer_info, context, SLOPPY,
restriction, RelocInfo::kNoPosition));
if (function_literal_only) {
// The actual body is wrapped, which shifts line numbers.
Handle<Script> script(Script::cast(fun->shared()->script()), isolate);
if (script->line_offset() == 0) {
int line_num = Script::GetLineNumber(script, source_offset);
script->set_line_offset(Smi::FromInt(-line_num));
}
}
return *fun;
}
......
......@@ -250,7 +250,7 @@ namespace internal {
F(DateCacheVersion, 0, 1) \
\
/* Globals */ \
F(CompileString, 3, 1) \
F(CompileString, 2, 1) \
\
/* Eval */ \
F(GlobalProxy, 1, 1) \
......
......@@ -176,7 +176,7 @@ function GlobalEval(x) {
var global_proxy = %GlobalProxy(global);
var f = %CompileString(x, false, 0);
var f = %CompileString(x, false);
if (!IS_FUNCTION(f)) return f;
return %_CallFunction(global_proxy, f);
......@@ -1832,7 +1832,7 @@ function FunctionBind(this_arg) { // Length is 1.
}
function NewFunctionFromString(arguments, function_token) {
function NewFunctionString(arguments, function_token) {
var n = arguments.length;
var p = '';
if (n > 1) {
......@@ -1849,20 +1849,21 @@ function NewFunctionFromString(arguments, function_token) {
// If the formal parameters include an unbalanced block comment, the
// function must be rejected. Since JavaScript does not allow nested
// comments we can include a trailing block comment to catch this.
p += '\n\x2f**\x2f';
p += '\n/' + '**/';
}
var body = (n > 0) ? ToString(arguments[n - 1]) : '';
var head = '(' + function_token + '(' + p + ') {\n';
var src = head + body + '\n})';
var global_proxy = %GlobalProxy(global);
var f = %_CallFunction(global_proxy, %CompileString(src, true, head.length));
%FunctionMarkNameShouldPrintAsAnonymous(f);
return f;
return '(' + function_token + '(' + p + ') {\n' + body + '\n})';
}
function FunctionConstructor(arg1) { // length == 1
return NewFunctionFromString(arguments, 'function');
var source = NewFunctionString(arguments, 'function');
var global_proxy = %GlobalProxy(global);
// Compile the string in the constructor and not a helper so that errors
// appear to come from here.
var f = %_CallFunction(global_proxy, %CompileString(source, true));
%FunctionMarkNameShouldPrintAsAnonymous(f);
return f;
}
......
......@@ -27,6 +27,6 @@
// Flags: --allow-natives-syntax
var single_function_good = "(function() { return 5; })";
%CompileString(single_function_good, true, 0);
%CompileString(single_function_good, true);
var single_function_bad = "(function() { return 5; })();";
%CompileString(single_function_bad, true, 0);
%CompileString(single_function_bad, true);
// Copyright 2014 the V8 project authors. All rights reserved.
// Copyright 2015 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.
......@@ -10,17 +10,50 @@ function test(expectation, f) {
} catch (e) {
stack = e.stack;
}
print(stack);
assertTrue(stack.indexOf("at eval (evaltest:" + expectation + ")") > 0);
}
test("1:5", new Function(
/*
(function() {
1 + reference_error //@ sourceURL=evaltest
})
*/
test("2:5", new Function(
'1 + reference_error //@ sourceURL=evaltest'));
test("2:6", new Function(
/*
(function(x
/\**\/) {
1 + reference_error //@ sourceURL=evaltest
})
*/
test("4:6", new Function(
'x', '\n 1 + reference_error //@ sourceURL=evaltest'));
test("2:6", new Function(
/*
(function(x
,z//
,y
/\**\/) {
1 + reference_error //@ sourceURL=evaltest
})
*/
test("7:6", new Function(
'x\n\n', "z//\n", "y", '\n 1 + reference_error //@ sourceURL=evaltest'));
test("1:5", new Function(
/*
(function(x/\*,z//
,y*\/
/\**\/) {
1 + reference_error //@ sourceURL=evaltest
})
*/
test("4:5", new Function(
'x/*', "z//\n", "y*/", '1 + reference_error //@ sourceURL=evaltest'));
/*
(function () {
1 + reference_error //@ sourceURL=evaltest5
})
*/
test("2:6", eval(
'(function () {\n 1 + reference_error //@ sourceURL=evaltest\n})'));
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