Revision: 8680
Author:   [email protected]
Date:     Tue Jul 19 01:19:31 2011
Log: Correctly mark functions from our natives files during compilation.

When creating a CompilationInfo we always have the script and can
determine if it is a natives script.

Now that all natives functions are recognized as such, many of them
are called with undefined as the receiver. We have to use different
filtering for builtins functions when printing stack traces.

Also, fixed one call of CALL_NON_FUNCTION to be correctly marked as a
method call (with fixed receiver). Now that CALL_NON_FUNCTION is
marked as a native function this caused the receiver to be undefined.

[email protected]
BUG=
TEST=

Review URL: http://codereview.chromium.org/7395030
http://code.google.com/p/v8/source/detail?r=8680

Modified:
 /branches/bleeding_edge/src/arm/code-stubs-arm.cc
 /branches/bleeding_edge/src/compiler.cc
 /branches/bleeding_edge/src/compiler.h
 /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc
 /branches/bleeding_edge/src/messages.js
 /branches/bleeding_edge/src/mips/code-stubs-mips.cc
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/src/x64/code-stubs-x64.cc
 /branches/bleeding_edge/test/mjsunit/regress/regress-798.js

=======================================
--- /branches/bleeding_edge/src/arm/code-stubs-arm.cc Wed Jul 13 04:08:25 2011 +++ /branches/bleeding_edge/src/arm/code-stubs-arm.cc Tue Jul 19 01:19:31 2011
@@ -4722,6 +4722,7 @@
   __ mov(r0, Operand(argc_));  // Setup the number of arguments.
   __ mov(r2, Operand(0, RelocInfo::NONE));
   __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION);
+  __ SetCallKind(r5, CALL_AS_METHOD);
   __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
           RelocInfo::CODE_TARGET);
 }
=======================================
--- /branches/bleeding_edge/src/compiler.cc     Thu Jun 30 04:52:00 2011
+++ /branches/bleeding_edge/src/compiler.cc     Tue Jul 19 01:19:31 2011
@@ -511,7 +511,6 @@
     info.SetPreParseData(pre_data);
     if (natives == NATIVES_CODE) {
       info.MarkAsAllowingNativesSyntax();
-      info.MarkAsNative();
     }
     result = MakeFunctionInfo(&info);
     if (extension == NULL && !result.is_null()) {
@@ -679,7 +678,6 @@
   info.SetFunction(literal);
   info.SetScope(literal->scope());
   if (literal->scope()->is_strict_mode()) info.MarkAsStrictMode();
-  if (script->type()->value() == Script::TYPE_NATIVE) info.MarkAsNative();

   LiveEditFunctionTracker live_edit_tracker(info.isolate(), literal);
   // Determine if the function can be lazily compiled. This is necessary to
=======================================
--- /branches/bleeding_edge/src/compiler.h      Mon Jun  6 08:43:08 2011
+++ /branches/bleeding_edge/src/compiler.h      Tue Jul 19 01:19:31 2011
@@ -173,9 +173,12 @@

   void Initialize(Mode mode) {
     mode_ = V8::UseCrankshaft() ? mode : NONOPT;
-    if (!shared_info_.is_null()) {
-      if (shared_info_->strict_mode()) MarkAsStrictMode();
-      if (shared_info_->native()) MarkAsNative();
+    ASSERT(!script_.is_null());
+    if (script_->type()->value() == Script::TYPE_NATIVE) {
+      MarkAsNative();
+    }
+    if (!shared_info_.is_null() && shared_info_->strict_mode()) {
+      MarkAsStrictMode();
     }
   }

=======================================
--- /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Wed Jul 13 04:08:25 2011 +++ /branches/bleeding_edge/src/ia32/code-stubs-ia32.cc Tue Jul 19 01:19:31 2011
@@ -4158,6 +4158,7 @@
   __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION);
   Handle<Code> adaptor =
       masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
+  __ SetCallKind(ecx, CALL_AS_METHOD);
   __ jmp(adaptor, RelocInfo::CODE_TARGET);
 }

=======================================
--- /branches/bleeding_edge/src/messages.js     Mon Jul 18 06:04:52 2011
+++ /branches/bleeding_edge/src/messages.js     Tue Jul 19 01:19:31 2011
@@ -1051,13 +1051,15 @@

 $Math.__proto__ = global.Object.prototype;

-DefineError(function Error() { });
-DefineError(function TypeError() { });
-DefineError(function RangeError() { });
-DefineError(function SyntaxError() { });
-DefineError(function ReferenceError() { });
-DefineError(function EvalError() { });
-DefineError(function URIError() { });
+// DefineError is a native function. Use explicit receiver. Otherwise
+// the receiver will be 'undefined'.
+this.DefineError(function Error() { });
+this.DefineError(function TypeError() { });
+this.DefineError(function RangeError() { });
+this.DefineError(function SyntaxError() { });
+this.DefineError(function ReferenceError() { });
+this.DefineError(function EvalError() { });
+this.DefineError(function URIError() { });

 $Error.captureStackTrace = captureStackTrace;

=======================================
--- /branches/bleeding_edge/src/mips/code-stubs-mips.cc Wed Jul 13 04:08:25 2011 +++ /branches/bleeding_edge/src/mips/code-stubs-mips.cc Tue Jul 19 01:19:31 2011
@@ -4913,6 +4913,7 @@
   __ li(a0, Operand(argc_));  // Setup the number of arguments.
   __ mov(a2, zero_reg);
   __ GetBuiltinEntry(a3, Builtins::CALL_NON_FUNCTION);
+  __ SetCallKind(t1, CALL_AS_METHOD);
   __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
           RelocInfo::CODE_TARGET);
 }
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Mon Jul 18 07:29:50 2011
+++ /branches/bleeding_edge/src/runtime.cc      Tue Jul 19 01:19:31 2011
@@ -12284,8 +12284,9 @@
 // call to this function is encountered it is skipped.  The seen_caller
 // in/out parameter is used to remember if the caller has been seen
 // yet.
-static bool ShowFrameInStackTrace(StackFrame* raw_frame, Object* caller,
-    bool* seen_caller) {
+static bool ShowFrameInStackTrace(StackFrame* raw_frame,
+                                  Object* caller,
+                                  bool* seen_caller) {
   // Only display JS frames.
   if (!raw_frame->is_java_script())
     return false;
@@ -12298,11 +12299,25 @@
     *seen_caller = true;
     return false;
   }
-  // Skip all frames until we've seen the caller.  Also, skip the most
-  // obvious builtin calls.  Some builtin calls (such as Number.ADD
-  // which is invoked using 'call') are very difficult to recognize
-  // so we're leaving them in for now.
-  return *seen_caller && !frame->receiver()->IsJSBuiltinsObject();
+  // Skip all frames until we've seen the caller.
+  if (!(*seen_caller)) return false;
+  // Also, skip the most obvious builtin calls. We recognize builtins
+  // as (1) functions called with the builtins object as the receiver and
+  // as (2) functions from native scripts called with undefined as the
+  // receiver (direct calls to helper functions in the builtins
+  // code). Some builtin calls (such as Number.ADD which is invoked
+  // using 'call') are very difficult to recognize so we're leaving
+  // them in for now.
+  if (frame->receiver()->IsJSBuiltinsObject()) {
+    return false;
+  }
+  JSFunction* fun = JSFunction::cast(raw_fun);
+  Object* raw_script = fun->shared()->script();
+  if (frame->receiver()->IsUndefined() && raw_script->IsScript()) {
+    int script_type = Script::cast(raw_script)->type()->value();
+    return script_type != Script::TYPE_NATIVE;
+  }
+  return true;
 }


=======================================
--- /branches/bleeding_edge/src/x64/code-stubs-x64.cc Wed Jul 13 04:08:25 2011 +++ /branches/bleeding_edge/src/x64/code-stubs-x64.cc Tue Jul 19 01:19:31 2011
@@ -3198,6 +3198,7 @@
   __ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION);
   Handle<Code> adaptor =
       Isolate::Current()->builtins()->ArgumentsAdaptorTrampoline();
+  __ SetCallKind(rcx, CALL_AS_METHOD);
   __ Jump(adaptor, RelocInfo::CODE_TARGET);
 }

=======================================
--- /branches/bleeding_edge/test/mjsunit/regress/regress-798.js Fri Mar 18 12:41:05 2011 +++ /branches/bleeding_edge/test/mjsunit/regress/regress-798.js Tue Jul 19 01:19:31 2011
@@ -106,4 +106,3 @@
 xx.a = 1;
 xx.b = 1;
 xx.c = 1;
-

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to