context = factory->NewWithContext(closure, context, extension);
}
+ i::Handle<i::Object> name_obj;
+ int line_offset = 0;
+ int column_offset = 0;
+ if (!source->resource_name.IsEmpty()) {
+ name_obj = Utils::OpenHandle(*(source->resource_name));
+ }
+ if (!source->resource_line_offset.IsEmpty()) {
+ line_offset = static_cast<int>(source->resource_line_offset->Value());
+ }
+ if (!source->resource_column_offset.IsEmpty()) {
+ column_offset = static_cast<int>(source->resource_column_offset->Value());
+ }
i::Handle<i::JSFunction> fun;
- has_pending_exception =
- !i::Compiler::GetFunctionFromEval(
- source_string, outer_info, context, i::SLOPPY,
- i::ONLY_SINGLE_FUNCTION_LITERAL, scope_position).ToHandle(&fun);
+ has_pending_exception = !i::Compiler::GetFunctionFromEval(
+ source_string, outer_info, context, i::SLOPPY,
+ i::ONLY_SINGLE_FUNCTION_LITERAL, line_offset,
+ column_offset - scope_position, name_obj,
+ source->resource_options).ToHandle(&fun);
+ if (has_pending_exception) {
+ isolate->ReportPendingMessages();
+ }
RETURN_ON_FAILED_EXECUTION(Function);
i::Handle<i::Object> result;
MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
Handle<String> source, Handle<SharedFunctionInfo> outer_info,
Handle<Context> context, LanguageMode language_mode,
- ParseRestriction restriction, int scope_position) {
+ ParseRestriction restriction, int line_offset, int column_offset,
+ Handle<Object> script_name, ScriptOriginOptions options) {
Isolate* isolate = source->GetIsolate();
int source_length = source->length();
isolate->counters()->total_eval_size()->Increment(source_length);
CompilationCache* compilation_cache = isolate->compilation_cache();
MaybeHandle<SharedFunctionInfo> maybe_shared_info =
compilation_cache->LookupEval(source, outer_info, context, language_mode,
- scope_position);
+ line_offset);
Handle<SharedFunctionInfo> shared_info;
if (!maybe_shared_info.ToHandle(&shared_info)) {
Handle<Script> script = isolate->factory()->NewScript(source);
+ if (!script_name.is_null()) {
+ script->set_name(*script_name);
+ script->set_line_offset(Smi::FromInt(line_offset));
+ script->set_column_offset(Smi::FromInt(column_offset));
+ }
+ script->set_origin_options(options);
Zone zone;
ParseInfo parse_info(&zone, script);
CompilationInfo info(&parse_info);
DCHECK(is_sloppy(language_mode) ||
is_strict(shared_info->language_mode()));
compilation_cache->PutEval(source, outer_info, context, shared_info,
- scope_position);
+ line_offset);
}
} else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) {
shared_info->ResetForNewContext(isolate->heap()->global_ic_age());
MUST_USE_RESULT static MaybeHandle<JSFunction> GetFunctionFromEval(
Handle<String> source, Handle<SharedFunctionInfo> outer_info,
Handle<Context> context, LanguageMode language_mode,
- ParseRestriction restriction, int scope_position);
+ ParseRestriction restriction, int line_offset, int column_offset = 0,
+ Handle<Object> script_name = Handle<Object>(),
+ ScriptOriginOptions options = ScriptOriginOptions());
// Compile a String source within a context.
static Handle<SharedFunctionInfo> CompileScript(
var start_position = %MessageGetStartPosition(message);
var location = script.locationFromPosition(start_position, false);
if (location == null) return -1;
- return start_position - location.start;
+ return location.column;
}
}
+TEST(CompileFunctionInContextScriptOrigin) {
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ v8::ScriptOrigin origin(v8_str("test"),
+ v8::Integer::New(CcTest::isolate(), 22),
+ v8::Integer::New(CcTest::isolate(), 41));
+ v8::ScriptCompiler::Source script_source(v8_str("throw new Error()"), origin);
+ v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
+ CcTest::isolate(), &script_source, env.local(), 0, NULL, 0, NULL);
+ CHECK(!fun.IsEmpty());
+ v8::TryCatch try_catch;
+ CcTest::isolate()->SetCaptureStackTraceForUncaughtExceptions(true);
+ fun->Call(env->Global(), 0, NULL);
+ CHECK(try_catch.HasCaught());
+ CHECK(!try_catch.Exception().IsEmpty());
+ v8::Local<v8::StackTrace> stack =
+ v8::Exception::GetStackTrace(try_catch.Exception());
+ CHECK(!stack.IsEmpty());
+ CHECK(stack->GetFrameCount() > 0);
+ v8::Local<v8::StackFrame> frame = stack->GetFrame(0);
+ CHECK_EQ(23, frame->GetLineNumber());
+ CHECK_EQ(42 + strlen("throw "), static_cast<unsigned>(frame->GetColumn()));
+}
+
+
#ifdef ENABLE_DISASSEMBLER
static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj,
const char* property_name) {