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);
}
}
}
}
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;
}
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;
}
/**
}
-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();
}
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());
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;
}
F(DateCacheVersion, 0, 1) \
\
/* Globals */ \
- F(CompileString, 3, 1) \
+ F(CompileString, 2, 1) \
\
/* Eval */ \
F(GlobalProxy, 1, 1) \
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);
}
-function NewFunctionFromString(arguments, function_token) {
+function NewFunctionString(arguments, function_token) {
var n = arguments.length;
var p = '';
if (n > 1) {
// 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;
}
// 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.
} 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})'));