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

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: Addressed moar comments by Andreas Rossberg. 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/proto-poison.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.
74 function InstallGetterSetter(object, name, getter, setter) {
75 %FunctionSetName(getter, name);
76 %FunctionSetName(setter, name);
77 %FunctionRemovePrototype(getter);
78 %FunctionRemovePrototype(setter);
79 %DefineOrRedefineAccessorProperty(object, name, getter, setter, DONT_ENUM);
80 %SetNativeFlag(getter);
81 %SetNativeFlag(setter);
82 }
83
84
73 // Prevents changes to the prototype of a built-in function. 85 // Prevents changes to the prototype of a built-in function.
74 // The "prototype" property of the function object is made non-configurable, 86 // The "prototype" property of the function object is made non-configurable,
75 // and the prototype object is made non-extensible. The latter prevents 87 // and the prototype object is made non-extensible. The latter prevents
76 // changing the __proto__ property. 88 // changing the __proto__ property.
77 function SetUpLockedPrototype(constructor, fields, methods) { 89 function SetUpLockedPrototype(constructor, fields, methods) {
78 %CheckIsBootstrapping(); 90 %CheckIsBootstrapping();
79 var prototype = constructor.prototype; 91 var prototype = constructor.prototype;
80 // Install functions first, because this function is used to initialize 92 // Install functions first, because this function is used to initialize
81 // PropertyDescriptor itself. 93 // PropertyDescriptor itself.
82 var property_count = (methods.length >> 1) + (fields ? fields.length : 0); 94 var property_count = (methods.length >> 1) + (fields ? fields.length : 0);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 if (IS_UNDEFINED(desc)) return desc; 400 if (IS_UNDEFINED(desc)) return desc;
389 401
390 if (IsDataDescriptor(desc)) { 402 if (IsDataDescriptor(desc)) {
391 return { value: desc.getValue(), 403 return { value: desc.getValue(),
392 writable: desc.isWritable(), 404 writable: desc.isWritable(),
393 enumerable: desc.isEnumerable(), 405 enumerable: desc.isEnumerable(),
394 configurable: desc.isConfigurable() }; 406 configurable: desc.isConfigurable() };
395 } 407 }
396 // Must be an AccessorDescriptor then. We never return a generic descriptor. 408 // Must be an AccessorDescriptor then. We never return a generic descriptor.
397 return { get: desc.getGet(), 409 return { get: desc.getGet(),
398 set: desc.getSet(), 410 set: desc.getSet() === ObjectSetProto ? ObjectPoisonProto
411 : desc.getSet(),
399 enumerable: desc.isEnumerable(), 412 enumerable: desc.isEnumerable(),
400 configurable: desc.isConfigurable() }; 413 configurable: desc.isConfigurable() };
401 } 414 }
402 415
403 416
404 // Harmony Proxies 417 // Harmony Proxies
405 function FromGenericPropertyDescriptor(desc) { 418 function FromGenericPropertyDescriptor(desc) {
406 if (IS_UNDEFINED(desc)) return desc; 419 if (IS_UNDEFINED(desc)) return desc;
407 var obj = new $Object(); 420 var obj = new $Object();
408 421
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 // Harmony egal. 1332 // Harmony egal.
1320 function ObjectIs(obj1, obj2) { 1333 function ObjectIs(obj1, obj2) {
1321 if (obj1 === obj2) { 1334 if (obj1 === obj2) {
1322 return (obj1 !== 0) || (1 / obj1 === 1 / obj2); 1335 return (obj1 !== 0) || (1 / obj1 === 1 / obj2);
1323 } else { 1336 } else {
1324 return (obj1 !== obj1) && (obj2 !== obj2); 1337 return (obj1 !== obj1) && (obj2 !== obj2);
1325 } 1338 }
1326 } 1339 }
1327 1340
1328 1341
1342 // Harmony __proto__ getter.
1343 function ObjectGetProto() {
1344 return %GetPrototype(this);
1345 }
1346
1347
1348 // Harmony __proto__ setter.
1349 function ObjectSetProto(obj) {
1350 return %SetPrototype(this, obj);
1351 }
1352
1353
1354 // Harmony __proto__ poison pill.
1355 function ObjectPoisonProto(obj) {
1356 throw MakeTypeError("proto_poison_pill", []);
1357 }
1358
1359
1329 %SetCode($Object, function(x) { 1360 %SetCode($Object, function(x) {
1330 if (%_IsConstructCall()) { 1361 if (%_IsConstructCall()) {
1331 if (x == null) return this; 1362 if (x == null) return this;
1332 return ToObject(x); 1363 return ToObject(x);
1333 } else { 1364 } else {
1334 if (x == null) return { }; 1365 if (x == null) return { };
1335 return ToObject(x); 1366 return ToObject(x);
1336 } 1367 }
1337 }); 1368 });
1338 1369
1339 %SetExpectedNumberOfProperties($Object, 4);
1340 1370
1341 // ---------------------------------------------------------------------------- 1371 // ----------------------------------------------------------------------------
1342 // Object 1372 // Object
1343 1373
1344 function SetUpObject() { 1374 function SetUpObject() {
1345 %CheckIsBootstrapping(); 1375 %CheckIsBootstrapping();
1346 // Set Up non-enumerable functions on the Object.prototype object. 1376
1377 %FunctionSetName(ObjectPoisonProto, "__proto__");
1378 %FunctionRemovePrototype(ObjectPoisonProto);
1379 %SetExpectedNumberOfProperties($Object, 4);
1380
1381 // Set up non-enumerable functions on the Object.prototype object.
1347 InstallFunctions($Object.prototype, DONT_ENUM, $Array( 1382 InstallFunctions($Object.prototype, DONT_ENUM, $Array(
1348 "toString", ObjectToString, 1383 "toString", ObjectToString,
1349 "toLocaleString", ObjectToLocaleString, 1384 "toLocaleString", ObjectToLocaleString,
1350 "valueOf", ObjectValueOf, 1385 "valueOf", ObjectValueOf,
1351 "hasOwnProperty", ObjectHasOwnProperty, 1386 "hasOwnProperty", ObjectHasOwnProperty,
1352 "isPrototypeOf", ObjectIsPrototypeOf, 1387 "isPrototypeOf", ObjectIsPrototypeOf,
1353 "propertyIsEnumerable", ObjectPropertyIsEnumerable, 1388 "propertyIsEnumerable", ObjectPropertyIsEnumerable,
1354 "__defineGetter__", ObjectDefineGetter, 1389 "__defineGetter__", ObjectDefineGetter,
1355 "__lookupGetter__", ObjectLookupGetter, 1390 "__lookupGetter__", ObjectLookupGetter,
1356 "__defineSetter__", ObjectDefineSetter, 1391 "__defineSetter__", ObjectDefineSetter,
1357 "__lookupSetter__", ObjectLookupSetter 1392 "__lookupSetter__", ObjectLookupSetter
1358 )); 1393 ));
1394 InstallGetterSetter($Object.prototype, "__proto__",
1395 ObjectGetProto, ObjectSetProto);
1396
1397 // Set up non-enumerable functions in the Object object.
1359 InstallFunctions($Object, DONT_ENUM, $Array( 1398 InstallFunctions($Object, DONT_ENUM, $Array(
1360 "keys", ObjectKeys, 1399 "keys", ObjectKeys,
1361 "create", ObjectCreate, 1400 "create", ObjectCreate,
1362 "defineProperty", ObjectDefineProperty, 1401 "defineProperty", ObjectDefineProperty,
1363 "defineProperties", ObjectDefineProperties, 1402 "defineProperties", ObjectDefineProperties,
1364 "freeze", ObjectFreeze, 1403 "freeze", ObjectFreeze,
1365 "getPrototypeOf", ObjectGetPrototypeOf, 1404 "getPrototypeOf", ObjectGetPrototypeOf,
1366 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, 1405 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
1367 "getOwnPropertyNames", ObjectGetOwnPropertyNames, 1406 "getOwnPropertyNames", ObjectGetOwnPropertyNames,
1368 "is", ObjectIs, 1407 "is", ObjectIs,
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 1790
1752 function SetUpFunction() { 1791 function SetUpFunction() {
1753 %CheckIsBootstrapping(); 1792 %CheckIsBootstrapping();
1754 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1793 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1755 "bind", FunctionBind, 1794 "bind", FunctionBind,
1756 "toString", FunctionToString 1795 "toString", FunctionToString
1757 )); 1796 ));
1758 } 1797 }
1759 1798
1760 SetUpFunction(); 1799 SetUpFunction();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/proto-poison.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698