From: kozyatinskiy Date: Wed, 1 Apr 2015 10:11:13 +0000 (-0700) Subject: Revert of Correctly compute line numbers in functions from the function constructor... X-Git-Tag: upstream/4.7.83~3476 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66d5519f7eef61ee892714254d878bf0fe2619f0;p=platform%2Fupstream%2Fv8.git 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} --- diff --git a/src/cpu-profiler.cc b/src/cpu-profiler.cc index 03d70521a..a8a57d1d6 100644 --- a/src/cpu-profiler.cc +++ b/src/cpu-profiler.cc @@ -277,8 +277,8 @@ void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag, Code* code, int position = static_cast(it.rinfo()->data()); if (position >= 0) { int pc_offset = static_cast(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); } } } diff --git a/src/generator.js b/src/generator.js index 9ab7dcb9a..fa6e9764a 100644 --- a/src/generator.js +++ b/src/generator.js @@ -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; } diff --git a/src/messages.js b/src/messages.js index 69be1c9ab..fe4098fb0 100644 --- a/src/messages.js +++ b/src/messages.js @@ -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; } /** diff --git a/src/objects.cc b/src/objects.cc index 41960e658..371adbe95 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -10367,31 +10367,27 @@ int Script::GetColumnNumber(Handle