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

Side by Side Diff: src/messages.js

Issue 258933007: Error stack getter should not overwrite itself with a data property. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-3294.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 var stackTraceLimit = $Error.stackTraceLimit; 1150 var stackTraceLimit = $Error.stackTraceLimit;
1151 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; 1151 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return;
1152 if (stackTraceLimit < 0 || stackTraceLimit > 10000) { 1152 if (stackTraceLimit < 0 || stackTraceLimit > 10000) {
1153 stackTraceLimit = 10000; 1153 stackTraceLimit = 10000;
1154 } 1154 }
1155 var stack = %CollectStackTrace(obj, 1155 var stack = %CollectStackTrace(obj,
1156 cons_opt ? cons_opt : captureStackTrace, 1156 cons_opt ? cons_opt : captureStackTrace,
1157 stackTraceLimit); 1157 stackTraceLimit);
1158 1158
1159 var error_string = FormatErrorString(obj); 1159 var error_string = FormatErrorString(obj);
1160 // The holder of this getter ('obj') may not be the receiver ('this').
1161 // When this getter is called the first time, we use the context values to
1162 // format a stack trace string and turn this accessor pair into a data
1163 // property (on the holder).
1164 var getter = function() {
1165 // Stack is still a raw array awaiting to be formatted.
1166 var result = FormatStackTrace(obj, error_string, GetStackFrames(stack));
1167 // Turn this accessor into a data property.
1168 %DefineOrRedefineDataProperty(obj, 'stack', result, NONE);
1169 // Release context values.
1170 stack = error_string = UNDEFINED;
1171 return result;
1172 };
1173 1160
1174 // Set the 'stack' property on the receiver. If the receiver is the same as 1161 // Set the 'stack' property on the receiver. If the receiver is the same as
1175 // holder of this setter, the accessor pair is turned into a data property. 1162 // holder of this setter, the accessor pair is turned into a data property.
1176 var setter = function(v) { 1163 var setter = function(v) {
1177 // Set data property on the receiver (not necessarily holder). 1164 // Set data property on the receiver (not necessarily holder).
1178 %DefineOrRedefineDataProperty(this, 'stack', v, NONE); 1165 %DefineOrRedefineDataProperty(this, 'stack', v, NONE);
1179 if (this === obj) { 1166 if (this === obj) {
1180 // Release context values if holder is the same as the receiver. 1167 // Release context values if holder is the same as the receiver.
1181 stack = error_string = UNDEFINED; 1168 stack = error_string = UNDEFINED;
1182 } 1169 }
1183 }; 1170 };
1184 1171
1172 // The holder of this getter ('obj') may not be the receiver ('this').
1173 // When this getter is called the first time, we use the context values to
1174 // format a stack trace string and turn this accessor pair into a data
1175 // property (on the holder).
ulan 2014/04/28 12:01:26 The comment is outdated now.
1176 var getter = function() {
1177 // Stack is still a raw array awaiting to be formatted.
1178 var result = FormatStackTrace(obj, error_string, GetStackFrames(stack));
1179 // Replace this accessor to return result directly.
1180 %DefineOrRedefineAccessorProperty(
1181 obj, 'stack', function() { return result }, setter, DONT_ENUM);
1182 // Release context values.
1183 stack = error_string = UNDEFINED;
1184 return result;
1185 };
1186
1185 %DefineOrRedefineAccessorProperty(obj, 'stack', getter, setter, DONT_ENUM); 1187 %DefineOrRedefineAccessorProperty(obj, 'stack', getter, setter, DONT_ENUM);
1186 } 1188 }
1187 1189
1188 1190
1189 function SetUpError() { 1191 function SetUpError() {
1190 // Define special error type constructors. 1192 // Define special error type constructors.
1191 1193
1192 var DefineError = function(f) { 1194 var DefineError = function(f) {
1193 // Store the error function in both the global object 1195 // Store the error function in both the global object
1194 // and the runtime object. The function is fetched 1196 // and the runtime object. The function is fetched
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 1315
1314 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); 1316 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]);
1315 1317
1316 // Boilerplate for exceptions for stack overflows. Used from 1318 // Boilerplate for exceptions for stack overflows. Used from
1317 // Isolate::StackOverflow(). 1319 // Isolate::StackOverflow().
1318 function SetUpStackOverflowBoilerplate() { 1320 function SetUpStackOverflowBoilerplate() {
1319 var boilerplate = MakeRangeError('stack_overflow', []); 1321 var boilerplate = MakeRangeError('stack_overflow', []);
1320 1322
1321 var error_string = boilerplate.name + ": " + boilerplate.message; 1323 var error_string = boilerplate.name + ": " + boilerplate.message;
1322 1324
1325 // Set the 'stack' property on the receiver. If the receiver is the same as
1326 // holder of this setter, the accessor pair is turned into a data property.
1327 var setter = function(v) {
1328 %DefineOrRedefineDataProperty(this, 'stack', v, NONE);
1329 // Tentatively clear the hidden property. If the receiver is the same as
1330 // holder, we release the raw stack trace this way.
1331 %GetAndClearOverflowedStackTrace(this);
1332 };
1333
1323 // The raw stack trace is stored as a hidden property on the holder of this 1334 // The raw stack trace is stored as a hidden property on the holder of this
1324 // getter, which may not be the same as the receiver. Find the holder to 1335 // getter, which may not be the same as the receiver. Find the holder to
1325 // retrieve the raw stack trace and then turn this accessor pair into a 1336 // retrieve the raw stack trace and then turn this accessor pair into a
1326 // data property. 1337 // data property.
1327 var getter = function() { 1338 var getter = function() {
1328 var holder = this; 1339 var holder = this;
1329 while (!IS_ERROR(holder)) { 1340 while (!IS_ERROR(holder)) {
1330 holder = %GetPrototype(holder); 1341 holder = %GetPrototype(holder);
1331 if (IS_NULL(holder)) return MakeSyntaxError('illegal_access', []); 1342 if (IS_NULL(holder)) return MakeSyntaxError('illegal_access', []);
1332 } 1343 }
1333 var stack = %GetAndClearOverflowedStackTrace(holder); 1344 var stack = %GetAndClearOverflowedStackTrace(holder);
1334 // We may not have captured any stack trace. 1345 // We may not have captured any stack trace.
1335 if (IS_UNDEFINED(stack)) return stack; 1346 if (IS_UNDEFINED(stack)) return stack;
1336 1347
1337 var result = FormatStackTrace(holder, error_string, GetStackFrames(stack)); 1348 var result = FormatStackTrace(holder, error_string, GetStackFrames(stack));
1338 // Replace this accessor with a data property. 1349 // Replace this accessor to return result directly.
1339 %DefineOrRedefineDataProperty(holder, 'stack', result, NONE); 1350 %DefineOrRedefineAccessorProperty(
1351 holder, 'stack', function() { return result }, setter, DONT_ENUM);
1340 return result; 1352 return result;
1341 }; 1353 };
1342 1354
1343 // Set the 'stack' property on the receiver. If the receiver is the same as
1344 // holder of this setter, the accessor pair is turned into a data property.
1345 var setter = function(v) {
1346 %DefineOrRedefineDataProperty(this, 'stack', v, NONE);
1347 // Tentatively clear the hidden property. If the receiver is the same as
1348 // holder, we release the raw stack trace this way.
1349 %GetAndClearOverflowedStackTrace(this);
1350 };
1351
1352 %DefineOrRedefineAccessorProperty( 1355 %DefineOrRedefineAccessorProperty(
1353 boilerplate, 'stack', getter, setter, DONT_ENUM); 1356 boilerplate, 'stack', getter, setter, DONT_ENUM);
1354 1357
1355 return boilerplate; 1358 return boilerplate;
1356 } 1359 }
1357 1360
1358 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); 1361 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-3294.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698