Commit 6ba8455e authored by erikcorry's avatar erikcorry Committed by Commit bot

Put getter functions on Script line-endings objects

This is a step towards having Blink no longer look directly at the
line endings array.  That prevented https://codereview.chromium.org/1137683003/
from landing.  Next step, after the roll, will be using these
functions in Blink.
R=jochen@chromium.org
BUG=

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

Cr-Commit-Position: refs/heads/master@{#29330}
parent 240ea089
......@@ -395,6 +395,16 @@ function ScriptLineCount() {
}
/**
* Returns the position of the nth line end.
* @return {number}
* Zero-based position of the nth line end in the script.
*/
function ScriptLineEnd(n) {
return this.line_ends[n];
}
/**
* If sourceURL comment is available returns sourceURL comment contents.
* Otherwise, script name is returned. See
......@@ -426,7 +436,8 @@ utils.SetUpLockedPrototype(Script, [
"sourceSlice", ScriptSourceSlice,
"sourceLine", ScriptSourceLine,
"lineCount", ScriptLineCount,
"nameOrSourceURL", ScriptNameOrSourceURL
"nameOrSourceURL", ScriptNameOrSourceURL,
"lineEnd", ScriptLineEnd
]
);
......
......@@ -398,6 +398,13 @@ static inline v8::Local<v8::Value> CompileRun(const char* source) {
}
// Helper functions that compile and run the source.
static inline v8::MaybeLocal<v8::Value> CompileRun(
v8::Local<v8::Context> context, const char* source) {
return v8::Script::Compile(v8_str(source))->Run(context);
}
// Compiles source as an ES6 module.
static inline v8::Local<v8::Value> CompileRunModule(const char* source) {
v8::ScriptCompiler::Source script_source(v8_str(source));
......
......@@ -6000,12 +6000,21 @@ TEST(DebugGetLoadedScripts) {
bool allow_natives_syntax = i::FLAG_allow_natives_syntax;
i::FLAG_allow_natives_syntax = true;
EnableDebugger();
CompileRun(
"var scripts = %DebugGetLoadedScripts();"
"var count = scripts.length;"
"for (var i = 0; i < count; ++i) {"
" scripts[i].line_ends;"
"}");
v8::MaybeLocal<v8::Value> result =
CompileRun(env.context(),
"var scripts = %DebugGetLoadedScripts();"
"var count = scripts.length;"
"for (var i = 0; i < count; ++i) {"
" var lines = scripts[i].lineCount();"
" if (lines < 1) throw 'lineCount';"
" var last = -1;"
" for (var j = 0; j < lines; ++j) {"
" var end = scripts[i].lineEnd(j);"
" if (last >= end) throw 'lineEnd';"
" last = end;"
" }"
"}");
CHECK(!result.IsEmpty());
DisableDebugger();
// Must not crash while accessing line_ends.
i::FLAG_allow_natives_syntax = allow_natives_syntax;
......
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