Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 function FromPropertyDescriptor(desc) { | 399 function FromPropertyDescriptor(desc) { |
| 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() === ObjectGetProto ? ObjectPoisonProto |
|
rossberg
2013/04/04 09:58:43
I don't think there is a need (or the intention) t
Michael Starzinger
2013/04/04 11:52:19
Done.
| |
| 398 set: desc.getSet(), | 410 : desc.getGet(), |
| 411 set: desc.getSet() === ObjectSetProto ? ObjectPoisonProto | |
| 412 : desc.getSet(), | |
| 399 enumerable: desc.isEnumerable(), | 413 enumerable: desc.isEnumerable(), |
| 400 configurable: desc.isConfigurable() }; | 414 configurable: desc.isConfigurable() }; |
| 401 } | 415 } |
| 402 | 416 |
| 403 | 417 |
| 404 // Harmony Proxies | 418 // Harmony Proxies |
| 405 function FromGenericPropertyDescriptor(desc) { | 419 function FromGenericPropertyDescriptor(desc) { |
| 406 if (IS_UNDEFINED(desc)) return desc; | 420 if (IS_UNDEFINED(desc)) return desc; |
| 407 var obj = new $Object(); | 421 var obj = new $Object(); |
| 408 | 422 |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1319 // Harmony egal. | 1333 // Harmony egal. |
| 1320 function ObjectIs(obj1, obj2) { | 1334 function ObjectIs(obj1, obj2) { |
| 1321 if (obj1 === obj2) { | 1335 if (obj1 === obj2) { |
| 1322 return (obj1 !== 0) || (1 / obj1 === 1 / obj2); | 1336 return (obj1 !== 0) || (1 / obj1 === 1 / obj2); |
| 1323 } else { | 1337 } else { |
| 1324 return (obj1 !== obj1) && (obj2 !== obj2); | 1338 return (obj1 !== obj1) && (obj2 !== obj2); |
| 1325 } | 1339 } |
| 1326 } | 1340 } |
| 1327 | 1341 |
| 1328 | 1342 |
| 1343 // Harmony __proto__ getter. | |
| 1344 function ObjectGetProto() { | |
| 1345 return %GetPrototype(this); | |
| 1346 } | |
| 1347 | |
| 1348 | |
| 1349 // Harmony __proto__ setter. | |
| 1350 function ObjectSetProto(obj) { | |
| 1351 return %SetPrototype(this, obj); | |
| 1352 } | |
| 1353 | |
| 1354 | |
| 1355 // Harmony __proto__ poison pill. | |
| 1356 function ObjectPoisonProto() { | |
| 1357 throw MakeTypeError("proto_poison_pill", []); | |
| 1358 } | |
| 1359 | |
| 1360 | |
| 1329 %SetCode($Object, function(x) { | 1361 %SetCode($Object, function(x) { |
| 1330 if (%_IsConstructCall()) { | 1362 if (%_IsConstructCall()) { |
| 1331 if (x == null) return this; | 1363 if (x == null) return this; |
| 1332 return ToObject(x); | 1364 return ToObject(x); |
| 1333 } else { | 1365 } else { |
| 1334 if (x == null) return { }; | 1366 if (x == null) return { }; |
| 1335 return ToObject(x); | 1367 return ToObject(x); |
| 1336 } | 1368 } |
| 1337 }); | 1369 }); |
| 1338 | 1370 |
| 1339 %SetExpectedNumberOfProperties($Object, 4); | |
| 1340 | 1371 |
| 1341 // ---------------------------------------------------------------------------- | 1372 // ---------------------------------------------------------------------------- |
| 1342 // Object | 1373 // Object |
| 1343 | 1374 |
| 1344 function SetUpObject() { | 1375 function SetUpObject() { |
| 1345 %CheckIsBootstrapping(); | 1376 %CheckIsBootstrapping(); |
| 1346 // Set Up non-enumerable functions on the Object.prototype object. | 1377 |
| 1378 %FunctionSetName(ObjectPoisonProto, "__proto__"); | |
| 1379 %FunctionRemovePrototype(ObjectPoisonProto); | |
| 1380 %SetExpectedNumberOfProperties($Object, 4); | |
| 1381 | |
| 1382 // Set up non-enumerable functions on the Object.prototype object. | |
| 1347 InstallFunctions($Object.prototype, DONT_ENUM, $Array( | 1383 InstallFunctions($Object.prototype, DONT_ENUM, $Array( |
| 1348 "toString", ObjectToString, | 1384 "toString", ObjectToString, |
| 1349 "toLocaleString", ObjectToLocaleString, | 1385 "toLocaleString", ObjectToLocaleString, |
| 1350 "valueOf", ObjectValueOf, | 1386 "valueOf", ObjectValueOf, |
| 1351 "hasOwnProperty", ObjectHasOwnProperty, | 1387 "hasOwnProperty", ObjectHasOwnProperty, |
| 1352 "isPrototypeOf", ObjectIsPrototypeOf, | 1388 "isPrototypeOf", ObjectIsPrototypeOf, |
| 1353 "propertyIsEnumerable", ObjectPropertyIsEnumerable, | 1389 "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
| 1354 "__defineGetter__", ObjectDefineGetter, | 1390 "__defineGetter__", ObjectDefineGetter, |
| 1355 "__lookupGetter__", ObjectLookupGetter, | 1391 "__lookupGetter__", ObjectLookupGetter, |
| 1356 "__defineSetter__", ObjectDefineSetter, | 1392 "__defineSetter__", ObjectDefineSetter, |
| 1357 "__lookupSetter__", ObjectLookupSetter | 1393 "__lookupSetter__", ObjectLookupSetter |
| 1358 )); | 1394 )); |
| 1395 InstallGetterSetter($Object.prototype, "__proto__", | |
| 1396 ObjectGetProto, ObjectSetProto); | |
| 1397 | |
| 1398 // Set up non-enumerable functions in the Object object. | |
| 1359 InstallFunctions($Object, DONT_ENUM, $Array( | 1399 InstallFunctions($Object, DONT_ENUM, $Array( |
| 1360 "keys", ObjectKeys, | 1400 "keys", ObjectKeys, |
| 1361 "create", ObjectCreate, | 1401 "create", ObjectCreate, |
| 1362 "defineProperty", ObjectDefineProperty, | 1402 "defineProperty", ObjectDefineProperty, |
| 1363 "defineProperties", ObjectDefineProperties, | 1403 "defineProperties", ObjectDefineProperties, |
| 1364 "freeze", ObjectFreeze, | 1404 "freeze", ObjectFreeze, |
| 1365 "getPrototypeOf", ObjectGetPrototypeOf, | 1405 "getPrototypeOf", ObjectGetPrototypeOf, |
| 1366 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, | 1406 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, |
| 1367 "getOwnPropertyNames", ObjectGetOwnPropertyNames, | 1407 "getOwnPropertyNames", ObjectGetOwnPropertyNames, |
| 1368 "is", ObjectIs, | 1408 "is", ObjectIs, |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1751 | 1791 |
| 1752 function SetUpFunction() { | 1792 function SetUpFunction() { |
| 1753 %CheckIsBootstrapping(); | 1793 %CheckIsBootstrapping(); |
| 1754 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1794 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1755 "bind", FunctionBind, | 1795 "bind", FunctionBind, |
| 1756 "toString", FunctionToString | 1796 "toString", FunctionToString |
| 1757 )); | 1797 )); |
| 1758 } | 1798 } |
| 1759 | 1799 |
| 1760 SetUpFunction(); | 1800 SetUpFunction(); |
| OLD | NEW |