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

Side by Side Diff: src/messages.js

Issue 11368136: Fix behavior of oneshot accessors of error objects. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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 | « no previous file | test/mjsunit/error-accessors.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 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 761
762 function GetStackTraceLine(recv, fun, pos, isGlobal) { 762 function GetStackTraceLine(recv, fun, pos, isGlobal) {
763 return new CallSite(recv, fun, pos).toString(); 763 return new CallSite(recv, fun, pos).toString();
764 } 764 }
765 765
766 // ---------------------------------------------------------------------------- 766 // ----------------------------------------------------------------------------
767 // Error implementation 767 // Error implementation
768 768
769 // Defines accessors for a property that is calculated the first time 769 // Defines accessors for a property that is calculated the first time
770 // the property is read. 770 // the property is read.
771 function DefineOneShotAccessor(obj, name, fun) { 771 function DefineOneShotAccessor(obj, name, value_factory) {
772 // Note that the accessors consistently operate on 'obj', not 'this'. 772 // Note that 'obj' may be different than 'this' since obj may be on the
773 // Since the object may occur in someone else's prototype chain we 773 // prototype chain of 'this'.
774 // can't rely on 'this' being the same as 'obj'.
775 var value;
776 var value_factory = fun;
777 var getter = function() { 774 var getter = function() {
778 if (value_factory == null) { 775 var value = value_factory(obj);
779 return value; 776 delete obj[name];
780 } 777 obj[name] = value;
781 value = value_factory(obj);
782 value_factory = null;
783 return value; 778 return value;
784 }; 779 };
785 var setter = function(v) { 780 var setter = function(v) {
786 value_factory = null; 781 // Set the property for 'this', ignoring this setter.
787 value = v; 782 %DefineOrRedefineDataProperty(this, name, v, NONE);
788 }; 783 };
789 %DefineOrRedefineAccessorProperty(obj, name, getter, setter, DONT_ENUM); 784 %DefineOrRedefineAccessorProperty(obj, name, getter, setter, DONT_ENUM);
790 } 785 }
791 786
792 function CallSite(receiver, fun, pos) { 787 function CallSite(receiver, fun, pos) {
793 this.receiver = receiver; 788 this.receiver = receiver;
794 this.fun = fun; 789 this.fun = fun;
795 this.pos = pos; 790 this.pos = pos;
796 } 791 }
797 792
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1265 throw e; 1260 throw e;
1266 } 1261 }
1267 } 1262 }
1268 1263
1269 1264
1270 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); 1265 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]);
1271 1266
1272 // Boilerplate for exceptions for stack overflows. Used from 1267 // Boilerplate for exceptions for stack overflows. Used from
1273 // Isolate::StackOverflow(). 1268 // Isolate::StackOverflow().
1274 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1269 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/error-accessors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698