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

Side by Side Diff: test/mjsunit/error-constructors.js

Issue 11358214: Remove 'type' and 'arguments' properties from Error object. (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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 18 matching lines...) Expand all
29 29
30 // Check that message and name are not enumerable on Error objects. 30 // Check that message and name are not enumerable on Error objects.
31 var desc = Object.getOwnPropertyDescriptor(Error.prototype, 'name'); 31 var desc = Object.getOwnPropertyDescriptor(Error.prototype, 'name');
32 assertFalse(desc['enumerable']); 32 assertFalse(desc['enumerable']);
33 desc = Object.getOwnPropertyDescriptor(Error.prototype, 'message'); 33 desc = Object.getOwnPropertyDescriptor(Error.prototype, 'message');
34 assertFalse(desc['enumerable']); 34 assertFalse(desc['enumerable']);
35 35
36 var e = new Error("foobar"); 36 var e = new Error("foobar");
37 desc = Object.getOwnPropertyDescriptor(e, 'message'); 37 desc = Object.getOwnPropertyDescriptor(e, 'message');
38 assertFalse(desc['enumerable']); 38 assertFalse(desc['enumerable']);
39 desc = Object.getOwnPropertyDescriptor(e, 'arguments');
40 assertFalse(desc['enumerable']);
41 desc = Object.getOwnPropertyDescriptor(e, 'type');
42 assertFalse(desc['enumerable']);
43 desc = Object.getOwnPropertyDescriptor(e, 'stack'); 39 desc = Object.getOwnPropertyDescriptor(e, 'stack');
44 assertFalse(desc['enumerable']); 40 assertFalse(desc['enumerable']);
45 41
46 var e = new Error(); 42 var e = new Error();
47 assertFalse(e.hasOwnProperty('message')); 43 assertFalse(e.hasOwnProperty('message'));
48 44
49 // name is not tested above, but in addition we should have no enumerable 45 // name is not tested above, but in addition we should have no enumerable
50 // properties, so we simply assert that. 46 // properties, so we simply assert that.
51 for (var v in e) { 47 for (var v in e) {
52 assertUnreachable(); 48 assertUnreachable();
53 } 49 }
54 50
55 // Check that error construction does not call setters for the 51 // Check that error construction does not call setters for the
56 // properties on error objects in prototypes. 52 // properties on error objects in prototypes.
57 function fail() { assertUnreachable(); }; 53 function fail() { assertUnreachable(); };
58 ReferenceError.prototype.__defineSetter__('name', fail); 54 ReferenceError.prototype.__defineSetter__('name', fail);
59 ReferenceError.prototype.__defineSetter__('message', fail); 55 ReferenceError.prototype.__defineSetter__('message', fail);
60 ReferenceError.prototype.__defineSetter__('type', fail);
61 ReferenceError.prototype.__defineSetter__('arguments', fail);
62 ReferenceError.prototype.__defineSetter__('stack', fail); 56 ReferenceError.prototype.__defineSetter__('stack', fail);
63 57
64 var e = new ReferenceError(); 58 var e = new ReferenceError();
65 assertTrue(e.hasOwnProperty('stack')); 59 assertTrue(e.hasOwnProperty('stack'));
66 assertTrue(e.hasOwnProperty('type'));
67 assertTrue(e.hasOwnProperty('arguments'));
68 60
69 var e = new ReferenceError('123'); 61 var e = new ReferenceError('123');
70 assertTrue(e.hasOwnProperty('message')); 62 assertTrue(e.hasOwnProperty('message'));
71 assertTrue(e.hasOwnProperty('stack')); 63 assertTrue(e.hasOwnProperty('stack'));
72 assertTrue(e.hasOwnProperty('type'));
73 assertTrue(e.hasOwnProperty('arguments'));
74 64
75 var e = %MakeReferenceError("my_test_error", [0, 1]); 65 var e = %MakeReferenceError("my_test_error", [0, 1]);
76 assertTrue(e.hasOwnProperty('stack')); 66 assertTrue(e.hasOwnProperty('stack'));
77 assertTrue(e.hasOwnProperty('type'));
78 assertTrue(e.hasOwnProperty('arguments'));
79 assertEquals("my_test_error", e.type)
80 67
81 // Check that intercepting property access from toString is prevented for 68 // Check that intercepting property access from toString is prevented for
82 // compiler errors. This is not specified, but allowing interception 69 // compiler errors. This is not specified, but allowing interception
83 // through a getter can leak error objects from different 70 // through a getter can leak error objects from different
84 // script tags in the same context in a browser setting. 71 // script tags in the same context in a browser setting.
85 var errors = [SyntaxError, ReferenceError, TypeError]; 72 var errors = [SyntaxError, ReferenceError, TypeError];
86 for (var i in errors) { 73 for (var i in errors) {
87 var name = errors[i].prototype.toString(); 74 var name = errors[i].prototype.toString();
88 // Monkey-patch prototype. 75 // Monkey-patch prototype.
89 var props = ["name", "message", "type", "arguments", "stack"]; 76 var props = ["name", "message", "stack"];
90 for (var j in props) { 77 for (var j in props) {
91 errors[i].prototype.__defineGetter__(props[j], fail); 78 errors[i].prototype.__defineGetter__(props[j], fail);
92 } 79 }
93 // String conversion should not invoke monkey-patched getters on prototype. 80 // String conversion should not invoke monkey-patched getters on prototype.
94 var e = new errors[i]; 81 var e = new errors[i];
95 assertEquals(name, e.toString()); 82 assertEquals(name, e.toString());
96 // Custom getters in actual objects are welcome. 83 // Custom getters in actual objects are welcome.
97 e.__defineGetter__("name", function() { return "mine"; }); 84 e.__defineGetter__("name", function() { return "mine"; });
98 assertEquals("mine", e.toString()); 85 assertEquals("mine", e.toString());
99 } 86 }
100 87
101 // Monkey-patching non-static errors should still be observable. 88 // Monkey-patching non-static errors should still be observable.
102 function MyError() {} 89 function MyError() {}
103 MyError.prototype = new Error; 90 MyError.prototype = new Error;
104 var errors = [Error, RangeError, EvalError, URIError, MyError]; 91 var errors = [Error, RangeError, EvalError, URIError, MyError];
105 for (var i in errors) { 92 for (var i in errors) {
106 errors[i].prototype.__defineGetter__("name", function() { return "my"; }); 93 errors[i].prototype.__defineGetter__("name", function() { return "my"; });
107 errors[i].prototype.__defineGetter__("message", function() { return "moo"; }); 94 errors[i].prototype.__defineGetter__("message", function() { return "moo"; });
108 var e = new errors[i]; 95 var e = new errors[i];
109 assertEquals("my: moo", e.toString()); 96 assertEquals("my: moo", e.toString());
110 } 97 }
111 98
112 99
113 Error.prototype.toString = Object.prototype.toString; 100 Error.prototype.toString = Object.prototype.toString;
114 assertEquals("[object Error]", Error.prototype.toString()); 101 assertEquals("[object Error]", Error.prototype.toString());
115 assertEquals(Object.prototype, Error.prototype.__proto__); 102 assertEquals(Object.prototype, Error.prototype.__proto__);
116 var e = new Error("foo"); 103 var e = new Error("foo");
117 assertEquals("[object Error]", e.toString()); 104 assertEquals("[object Error]", e.toString());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698