Reviewers: aandrey,

Description:
Correctly compute line numbers in functions from the function constructor.

[email protected]
BUG=chromium:109362

Please review this at https://codereview.chromium.org/701093003/

Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+13, -15 lines):
  M src/compiler.cc
  M src/runtime/runtime.h
  M src/runtime/runtime-function.cc
  M src/v8natives.js
  A + test/mjsunit/regress/regress-crbug-109362.js


Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index ba5f3fd56ea511d39162be59ff77f22f85cc9c22..6024a8d272b202fe77b88e9f856a5b50ebe7ad32 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -1152,6 +1152,12 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval( compilation_cache->PutEval(source, outer_info, context, shared_info,
                                    scope_position);
       }
+      if (restriction == ONLY_SINGLE_FUNCTION_LITERAL) {
+        // Function constructor.
+        shared_info->set_name_should_print_as_anonymous(true);
+        // The actual body is wrapped, which adds a line.
+        script->set_line_offset(Smi::FromInt(-1));
+      }
     }
   } else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) {
     shared_info->ResetForNewContext(isolate->heap()->global_ic_age());
Index: src/runtime/runtime-function.cc
diff --git a/src/runtime/runtime-function.cc b/src/runtime/runtime-function.cc index e25b6592e00130ffb52f7d5157af2048e487bde8..93f1cde55bbe90323dc074eada2ad6a57dc797dd 100644
--- a/src/runtime/runtime-function.cc
+++ b/src/runtime/runtime-function.cc
@@ -106,15 +106,6 @@ RUNTIME_FUNCTION(Runtime_FunctionNameShouldPrintAsAnonymous) {
 }


-RUNTIME_FUNCTION(Runtime_FunctionMarkNameShouldPrintAsAnonymous) {
-  SealHandleScope shs(isolate);
-  DCHECK(args.length() == 1);
-  CONVERT_ARG_CHECKED(JSFunction, f, 0);
-  f->shared()->set_name_should_print_as_anonymous(true);
-  return isolate->heap()->undefined_value();
-}
-
-
 RUNTIME_FUNCTION(Runtime_FunctionIsArrow) {
   SealHandleScope shs(isolate);
   DCHECK(args.length() == 1);
Index: src/runtime/runtime.h
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index 5d6ccac709f235e85cc87230283e63cb7174505b..f66b0790edfb253308d54aadc6ee3a3972a6d2c3 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -210,7 +210,6 @@ namespace internal {
   F(FunctionGetName, 1, 1)                             \
   F(FunctionSetName, 2, 1)                             \
   F(FunctionNameShouldPrintAsAnonymous, 1, 1)          \
-  F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1)      \
   F(FunctionIsGenerator, 1, 1)                         \
   F(FunctionIsArrow, 1, 1)                             \
   F(FunctionIsConciseMethod, 1, 1)                     \
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 6215ab09681f9becca17d073c7ac52406b9cf60c..40199bc8759999e0cad1bb81e83f7f15bfac1120 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -1846,7 +1846,7 @@ function NewFunctionString(arguments, function_token) {
     // 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/' + '**/';
+    p += '/**/';
   }
   var body = (n > 0) ? ToString(arguments[n - 1]) : '';
   return '(' + function_token + '(' + p + ') {\n' + body + '\n})';
@@ -1859,7 +1859,6 @@ function FunctionConstructor(arg1) {  // length == 1
   // 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;
 }

Index: test/mjsunit/regress/regress-crbug-109362.js
diff --git a/test/mjsunit/regress/regress-3159.js b/test/mjsunit/regress/regress-crbug-109362.js
similarity index 53%
copy from test/mjsunit/regress/regress-3159.js
copy to test/mjsunit/regress/regress-crbug-109362.js
index cfc8a39b8d011533ed94fcaf11669814c9cbc4d2..0f7eef15b7a1796c352d28d6aec0b10ace7938d0 100644
--- a/test/mjsunit/regress/regress-3159.js
+++ b/test/mjsunit/regress/regress-crbug-109362.js
@@ -2,9 +2,12 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.

+var g = new Function('1 + reference_error //@ sourceURL=evaltest');
+var stack;
 try {
-  new Uint32Array(new ArrayBuffer(1), 2, 3);
+  g();
 } catch (e) {
-  assertEquals("start offset of Uint32Array should be a multiple of 4",
-               e.message);
+  stack = e.stack;
 }
+
+assertTrue(stack.indexOf("at eval (evaltest:1:5)") > 0);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to