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

Side by Side Diff: src/v8natives.js

Issue 13533004: Make __proto__ a real JavaScript accessor property. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add regression test for issue 2606. Created 7 years, 8 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 | « src/runtime.cc ('k') | test/mjsunit/regress/regress-2606.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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 var f = functions[i + 1]; 54 var f = functions[i + 1];
55 %FunctionSetName(f, key); 55 %FunctionSetName(f, key);
56 %FunctionRemovePrototype(f); 56 %FunctionRemovePrototype(f);
57 %SetProperty(object, key, f, attributes); 57 %SetProperty(object, key, f, attributes);
58 %SetNativeFlag(f); 58 %SetNativeFlag(f);
59 } 59 }
60 %ToFastProperties(object); 60 %ToFastProperties(object);
61 } 61 }
62 62
63 63
64 // Helper function to install a getter only property. 64 // Helper function to install a getter-only accessor property.
65 function InstallGetter(object, name, getter) { 65 function InstallGetter(object, name, getter) {
66 %FunctionSetName(getter, name); 66 %FunctionSetName(getter, name);
67 %FunctionRemovePrototype(getter); 67 %FunctionRemovePrototype(getter);
68 %DefineOrRedefineAccessorProperty(object, name, getter, null, DONT_ENUM); 68 %DefineOrRedefineAccessorProperty(object, name, getter, null, DONT_ENUM);
69 %SetNativeFlag(getter); 69 %SetNativeFlag(getter);
70 } 70 }
71 71
72 72
73 // Helper function to install a getter/setter accessor property/
rossberg 2013/04/03 13:42:23 Nit: / -> . at the end
Michael Starzinger 2013/04/04 09:48:02 Done.
74 function InstallGetterSetter(object, name, getter, setter) {
rossberg 2013/04/03 13:42:23 Maybe cook up names that make clear that this func
Michael Starzinger 2013/04/04 09:48:02 Done. Oops, totally missed the boilerplate to adap
75 %DefineOrRedefineAccessorProperty(object, name, getter, setter, DONT_ENUM);
76 }
77
78
73 // Prevents changes to the prototype of a built-in function. 79 // Prevents changes to the prototype of a built-in function.
74 // The "prototype" property of the function object is made non-configurable, 80 // The "prototype" property of the function object is made non-configurable,
75 // and the prototype object is made non-extensible. The latter prevents 81 // and the prototype object is made non-extensible. The latter prevents
76 // changing the __proto__ property. 82 // changing the __proto__ property.
77 function SetUpLockedPrototype(constructor, fields, methods) { 83 function SetUpLockedPrototype(constructor, fields, methods) {
78 %CheckIsBootstrapping(); 84 %CheckIsBootstrapping();
79 var prototype = constructor.prototype; 85 var prototype = constructor.prototype;
80 // Install functions first, because this function is used to initialize 86 // Install functions first, because this function is used to initialize
81 // PropertyDescriptor itself. 87 // PropertyDescriptor itself.
82 var property_count = (methods.length >> 1) + (fields ? fields.length : 0); 88 var property_count = (methods.length >> 1) + (fields ? fields.length : 0);
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 // Harmony egal. 1325 // Harmony egal.
1320 function ObjectIs(obj1, obj2) { 1326 function ObjectIs(obj1, obj2) {
1321 if (obj1 === obj2) { 1327 if (obj1 === obj2) {
1322 return (obj1 !== 0) || (1 / obj1 === 1 / obj2); 1328 return (obj1 !== 0) || (1 / obj1 === 1 / obj2);
1323 } else { 1329 } else {
1324 return (obj1 !== obj1) && (obj2 !== obj2); 1330 return (obj1 !== obj1) && (obj2 !== obj2);
1325 } 1331 }
1326 } 1332 }
1327 1333
1328 1334
1335 // Harmony __proto__ getter.
1336 function ObjectGetProto() {
1337 return %GetPrototype(this);
1338 }
1339
1340
1341 // Harmony __proto__ setter.
1342 function ObjectSetProto(obj) {
1343 return %SetPrototype(this, obj);
1344 }
1345
1346
1329 %SetCode($Object, function(x) { 1347 %SetCode($Object, function(x) {
1330 if (%_IsConstructCall()) { 1348 if (%_IsConstructCall()) {
1331 if (x == null) return this; 1349 if (x == null) return this;
1332 return ToObject(x); 1350 return ToObject(x);
1333 } else { 1351 } else {
1334 if (x == null) return { }; 1352 if (x == null) return { };
1335 return ToObject(x); 1353 return ToObject(x);
1336 } 1354 }
1337 }); 1355 });
1338 1356
1339 %SetExpectedNumberOfProperties($Object, 4);
1340 1357
1341 // ---------------------------------------------------------------------------- 1358 // ----------------------------------------------------------------------------
1342 // Object 1359 // Object
1343 1360
1344 function SetUpObject() { 1361 function SetUpObject() {
1345 %CheckIsBootstrapping(); 1362 %CheckIsBootstrapping();
1346 // Set Up non-enumerable functions on the Object.prototype object. 1363
1364 %SetExpectedNumberOfProperties($Object, 4);
1365
1366 // Set up non-enumerable functions on the Object.prototype object.
1347 InstallFunctions($Object.prototype, DONT_ENUM, $Array( 1367 InstallFunctions($Object.prototype, DONT_ENUM, $Array(
1348 "toString", ObjectToString, 1368 "toString", ObjectToString,
1349 "toLocaleString", ObjectToLocaleString, 1369 "toLocaleString", ObjectToLocaleString,
1350 "valueOf", ObjectValueOf, 1370 "valueOf", ObjectValueOf,
1351 "hasOwnProperty", ObjectHasOwnProperty, 1371 "hasOwnProperty", ObjectHasOwnProperty,
1352 "isPrototypeOf", ObjectIsPrototypeOf, 1372 "isPrototypeOf", ObjectIsPrototypeOf,
1353 "propertyIsEnumerable", ObjectPropertyIsEnumerable, 1373 "propertyIsEnumerable", ObjectPropertyIsEnumerable,
1354 "__defineGetter__", ObjectDefineGetter, 1374 "__defineGetter__", ObjectDefineGetter,
1355 "__lookupGetter__", ObjectLookupGetter, 1375 "__lookupGetter__", ObjectLookupGetter,
1356 "__defineSetter__", ObjectDefineSetter, 1376 "__defineSetter__", ObjectDefineSetter,
1357 "__lookupSetter__", ObjectLookupSetter 1377 "__lookupSetter__", ObjectLookupSetter
1358 )); 1378 ));
1379 InstallGetterSetter($Object.prototype, "__proto__",
1380 ObjectGetProto, ObjectSetProto);
1381
1382 // Set up non-enumerable functions in the Object object.
1359 InstallFunctions($Object, DONT_ENUM, $Array( 1383 InstallFunctions($Object, DONT_ENUM, $Array(
1360 "keys", ObjectKeys, 1384 "keys", ObjectKeys,
1361 "create", ObjectCreate, 1385 "create", ObjectCreate,
1362 "defineProperty", ObjectDefineProperty, 1386 "defineProperty", ObjectDefineProperty,
1363 "defineProperties", ObjectDefineProperties, 1387 "defineProperties", ObjectDefineProperties,
1364 "freeze", ObjectFreeze, 1388 "freeze", ObjectFreeze,
1365 "getPrototypeOf", ObjectGetPrototypeOf, 1389 "getPrototypeOf", ObjectGetPrototypeOf,
1366 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, 1390 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
1367 "getOwnPropertyNames", ObjectGetOwnPropertyNames, 1391 "getOwnPropertyNames", ObjectGetOwnPropertyNames,
1368 "is", ObjectIs, 1392 "is", ObjectIs,
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 1775
1752 function SetUpFunction() { 1776 function SetUpFunction() {
1753 %CheckIsBootstrapping(); 1777 %CheckIsBootstrapping();
1754 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1778 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1755 "bind", FunctionBind, 1779 "bind", FunctionBind,
1756 "toString", FunctionToString 1780 "toString", FunctionToString
1757 )); 1781 ));
1758 } 1782 }
1759 1783
1760 SetUpFunction(); 1784 SetUpFunction();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/regress/regress-2606.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698