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

Unified Diff: src/messages.js

Issue 360033002: Revert "Fix stack trace accessor behavior." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/isolate.cc ('k') | src/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index 61ba6ce3860413e3b978e7ae8d50428b4fbefcde..8f83a62107ee93ecfd00967972cf7f6490b499c1 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -1080,8 +1080,7 @@ function GetStackFrames(raw_stack) {
var formatting_custom_stack_trace = false;
-function FormatStackTrace(obj, raw_stack) {
- var frames = GetStackFrames(raw_stack);
+function FormatStackTrace(obj, error_string, frames) {
if (IS_FUNCTION($Error.prepareStackTrace) && !formatting_custom_stack_trace) {
var array = [];
%MoveArrayContents(frames, array);
@@ -1098,7 +1097,7 @@ function FormatStackTrace(obj, raw_stack) {
}
var lines = new InternalArray();
- lines.push(FormatErrorString(obj));
+ lines.push(error_string);
for (var i = 0; i < frames.length; i++) {
var frame = frames[i];
var line;
@@ -1133,45 +1132,45 @@ function GetTypeName(receiver, requireConstructor) {
}
-var stack_trace_symbol; // Set during bootstrapping.
-var formatted_stack_trace_symbol = NEW_PRIVATE("formatted stack trace");
-
-
-// Format the stack trace if not yet done, and return it.
-// Cache the formatted stack trace on the holder.
-function StackTraceGetter() {
- var formatted_stack_trace = GET_PRIVATE(this, formatted_stack_trace_symbol);
- if (IS_UNDEFINED(formatted_stack_trace)) {
- var holder = this;
- while (!HAS_PRIVATE(holder, stack_trace_symbol)) {
- holder = %GetPrototype(holder);
- if (!holder) return UNDEFINED;
- }
- var stack_trace = GET_PRIVATE(holder, stack_trace_symbol);
- if (IS_UNDEFINED(stack_trace)) return UNDEFINED;
- formatted_stack_trace = FormatStackTrace(holder, stack_trace);
- SET_PRIVATE(holder, stack_trace_symbol, UNDEFINED);
- SET_PRIVATE(holder, formatted_stack_trace_symbol, formatted_stack_trace);
- }
- return formatted_stack_trace;
-};
-
-
-// If the receiver equals the holder, set the formatted stack trace that the
-// getter returns.
-function StackTraceSetter(v) {
- if (HAS_PRIVATE(this, stack_trace_symbol)) {
- SET_PRIVATE(this, stack_trace_symbol, UNDEFINED);
- SET_PRIVATE(this, formatted_stack_trace_symbol, v);
+function captureStackTrace(obj, cons_opt) {
+ var stackTraceLimit = $Error.stackTraceLimit;
+ if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return;
+ if (stackTraceLimit < 0 || stackTraceLimit > 10000) {
+ stackTraceLimit = 10000;
}
-};
+ var stack = %CollectStackTrace(obj,
+ cons_opt ? cons_opt : captureStackTrace,
+ stackTraceLimit);
+
+ var error_string = FormatErrorString(obj);
+
+ // Set the 'stack' property on the receiver. If the receiver is the same as
+ // holder of this setter, the accessor pair is turned into a data property.
+ var setter = function(v) {
+ // Set data property on the receiver (not necessarily holder).
+ %DefineDataPropertyUnchecked(this, 'stack', v, NONE);
+ if (this === obj) {
+ // Release context values if holder is the same as the receiver.
+ stack = error_string = UNDEFINED;
+ }
+ };
+ // The holder of this getter ('obj') may not be the receiver ('this').
+ // When this getter is called the first time, we use the context values to
+ // format a stack trace string and turn this accessor pair into a data
+ // property (on the holder).
+ var getter = function() {
+ // Stack is still a raw array awaiting to be formatted.
+ var result = FormatStackTrace(obj, error_string, GetStackFrames(stack));
+ // Replace this accessor to return result directly.
+ %DefineAccessorPropertyUnchecked(
+ obj, 'stack', function() { return result }, setter, DONT_ENUM);
+ // Release context values.
+ stack = error_string = UNDEFINED;
+ return result;
+ };
-function captureStackTrace(obj, cons_opt) {
- // Define accessors first, as this may fail and throw.
- ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter,
- set: StackTraceSetter});
- %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace);
+ %DefineAccessorPropertyUnchecked(obj, 'stack', getter, setter, DONT_ENUM);
}
@@ -1307,8 +1306,40 @@ InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]);
function SetUpStackOverflowBoilerplate() {
var boilerplate = MakeRangeError('stack_overflow', []);
+ var error_string = boilerplate.name + ": " + boilerplate.message;
+
+ // Set the 'stack' property on the receiver. If the receiver is the same as
+ // holder of this setter, the accessor pair is turned into a data property.
+ var setter = function(v) {
+ %DefineDataPropertyUnchecked(this, 'stack', v, NONE);
+ // Tentatively clear the hidden property. If the receiver is the same as
+ // holder, we release the raw stack trace this way.
+ %GetAndClearOverflowedStackTrace(this);
+ };
+
+ // The raw stack trace is stored as a hidden property on the holder of this
+ // getter, which may not be the same as the receiver. Find the holder to
+ // retrieve the raw stack trace and then turn this accessor pair into a
+ // data property.
+ var getter = function() {
+ var holder = this;
+ while (!IS_ERROR(holder)) {
+ holder = %GetPrototype(holder);
+ if (IS_NULL(holder)) return MakeSyntaxError('illegal_access', []);
+ }
+ var stack = %GetAndClearOverflowedStackTrace(holder);
+ // We may not have captured any stack trace.
+ if (IS_UNDEFINED(stack)) return stack;
+
+ var result = FormatStackTrace(holder, error_string, GetStackFrames(stack));
+ // Replace this accessor to return result directly.
+ %DefineAccessorPropertyUnchecked(
+ holder, 'stack', function() { return result }, setter, DONT_ENUM);
+ return result;
+ };
+
%DefineAccessorPropertyUnchecked(
- boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM);
+ boilerplate, 'stack', getter, setter, DONT_ENUM);
return boilerplate;
}
« no previous file with comments | « src/isolate.cc ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698