Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: src/runtime/runtime-compiler.cc

Issue 701093003: Correctly compute line numbers in functions from the function constructor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime/runtime.h ('k') | src/v8natives.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/deoptimizer.h" 9 #include "src/deoptimizer.h"
10 #include "src/frames.h" 10 #include "src/frames.h"
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } else { 340 } else {
341 // Callback set. Let it decide if code generation is allowed. 341 // Callback set. Let it decide if code generation is allowed.
342 VMState<EXTERNAL> state(isolate); 342 VMState<EXTERNAL> state(isolate);
343 return callback(v8::Utils::ToLocal(context)); 343 return callback(v8::Utils::ToLocal(context));
344 } 344 }
345 } 345 }
346 346
347 347
348 RUNTIME_FUNCTION(Runtime_CompileString) { 348 RUNTIME_FUNCTION(Runtime_CompileString) {
349 HandleScope scope(isolate); 349 HandleScope scope(isolate);
350 DCHECK(args.length() == 2); 350 DCHECK(args.length() == 3);
351 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); 351 CONVERT_ARG_HANDLE_CHECKED(String, source, 0);
352 CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1); 352 CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1);
353 CONVERT_SMI_ARG_CHECKED(source_offset, 2);
353 354
354 // Extract native context. 355 // Extract native context.
355 Handle<Context> context(isolate->native_context()); 356 Handle<Context> context(isolate->native_context());
356 357
357 // Check if native context allows code generation from 358 // Check if native context allows code generation from
358 // strings. Throw an exception if it doesn't. 359 // strings. Throw an exception if it doesn't.
359 if (context->allow_code_gen_from_strings()->IsFalse() && 360 if (context->allow_code_gen_from_strings()->IsFalse() &&
360 !CodeGenerationFromStringsAllowed(isolate, context)) { 361 !CodeGenerationFromStringsAllowed(isolate, context)) {
361 Handle<Object> error_message = 362 Handle<Object> error_message =
362 context->ErrorMessageForCodeGenerationFromStrings(); 363 context->ErrorMessageForCodeGenerationFromStrings();
363 THROW_NEW_ERROR_RETURN_FAILURE( 364 THROW_NEW_ERROR_RETURN_FAILURE(
364 isolate, NewEvalError("code_gen_from_strings", 365 isolate, NewEvalError("code_gen_from_strings",
365 HandleVector<Object>(&error_message, 1))); 366 HandleVector<Object>(&error_message, 1)));
366 } 367 }
367 368
368 // Compile source string in the native context. 369 // Compile source string in the native context.
369 ParseRestriction restriction = function_literal_only 370 ParseRestriction restriction = function_literal_only
370 ? ONLY_SINGLE_FUNCTION_LITERAL 371 ? ONLY_SINGLE_FUNCTION_LITERAL
371 : NO_PARSE_RESTRICTION; 372 : NO_PARSE_RESTRICTION;
372 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate); 373 Handle<SharedFunctionInfo> outer_info(context->closure()->shared(), isolate);
373 Handle<JSFunction> fun; 374 Handle<JSFunction> fun;
374 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 375 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
375 isolate, fun, 376 isolate, fun,
376 Compiler::GetFunctionFromEval(source, outer_info, context, SLOPPY, 377 Compiler::GetFunctionFromEval(source, outer_info, context, SLOPPY,
377 restriction, RelocInfo::kNoPosition)); 378 restriction, RelocInfo::kNoPosition));
379 if (function_literal_only) {
380 // The actual body is wrapped, which shifts line numbers.
381 Handle<Script> script(Script::cast(fun->shared()->script()), isolate);
382 if (script->line_offset() == 0) {
383 int line_num = Script::GetLineNumber(script, source_offset);
384 script->set_line_offset(Smi::FromInt(-line_num));
385 }
386 }
378 return *fun; 387 return *fun;
379 } 388 }
380 389
381 390
382 static ObjectPair CompileGlobalEval(Isolate* isolate, Handle<String> source, 391 static ObjectPair CompileGlobalEval(Isolate* isolate, Handle<String> source,
383 Handle<SharedFunctionInfo> outer_info, 392 Handle<SharedFunctionInfo> outer_info,
384 Handle<Object> receiver, 393 Handle<Object> receiver,
385 StrictMode strict_mode, 394 StrictMode strict_mode,
386 int scope_position) { 395 int scope_position) {
387 Handle<Context> context = Handle<Context>(isolate->context()); 396 Handle<Context> context = Handle<Context>(isolate->context());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 DCHECK(args.smi_at(4) == SLOPPY || args.smi_at(4) == STRICT); 442 DCHECK(args.smi_at(4) == SLOPPY || args.smi_at(4) == STRICT);
434 StrictMode strict_mode = static_cast<StrictMode>(args.smi_at(4)); 443 StrictMode strict_mode = static_cast<StrictMode>(args.smi_at(4));
435 DCHECK(args[5]->IsSmi()); 444 DCHECK(args[5]->IsSmi());
436 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(), 445 Handle<SharedFunctionInfo> outer_info(args.at<JSFunction>(2)->shared(),
437 isolate); 446 isolate);
438 return CompileGlobalEval(isolate, args.at<String>(1), outer_info, 447 return CompileGlobalEval(isolate, args.at<String>(1), outer_info,
439 args.at<Object>(3), strict_mode, args.smi_at(5)); 448 args.at<Object>(3), strict_mode, args.smi_at(5));
440 } 449 }
441 } 450 }
442 } // namespace v8::internal 451 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698