Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 21 matching lines...) Expand all Loading... | |
| 32 // have only unconfigurable properties on the prototype, and the methods | 32 // have only unconfigurable properties on the prototype, and the methods |
| 33 // are also non-writable. | 33 // are also non-writable. |
| 34 | 34 |
| 35 var names = Object.getOwnPropertyNames(builtins); | 35 var names = Object.getOwnPropertyNames(builtins); |
| 36 | 36 |
| 37 function isFunction(obj) { | 37 function isFunction(obj) { |
| 38 return typeof obj == "function"; | 38 return typeof obj == "function"; |
| 39 } | 39 } |
| 40 | 40 |
| 41 function isV8Native(name) { | 41 function isV8Native(name) { |
| 42 return name == "GeneratorFunctionPrototype" || | 42 return name == "GeneratorFunction" || |
| 43 name == "GeneratorFunctionPrototype" || | |
| 43 name == "SetIterator" || | 44 name == "SetIterator" || |
| 44 name == "MapIterator" || | 45 name == "MapIterator" || |
| 45 name == "ArrayIterator" || | 46 name == "ArrayIterator" || |
| 46 name == "StringIterator"; | 47 name == "StringIterator"; |
| 47 } | 48 } |
| 49 var V8NativePrototypes = { | |
| 50 GeneratorFunction: Function.prototype, | |
| 51 // TODO: Update the following values to the %IteratorPrototype% intrinsic | |
|
caitp (gmail)
2015/04/06 18:05:05
TODO(name): ...
| |
| 52 // once it is implemented. | |
| 53 // Issue 3568: Generator Prototype should have an object between itself | |
|
caitp (gmail)
2015/04/06 18:07:03
bug numbers might be iffy, especially if v8 has to
arv (Not doing code reviews)
2015/04/06 18:15:14
Bug numbers are fine. We have them all over. It mi
| |
| 54 // and Object.prototype | |
| 55 GeneratorFunctionPrototype: Object.prototype, | |
| 56 SetIterator: Object.prototype, | |
| 57 MapIterator: Object.prototype, | |
| 58 ArrayIterator: Object.prototype, | |
| 59 StringIterator: Object.prototype | |
| 60 }; | |
| 48 | 61 |
| 49 function checkConstructor(func, name) { | 62 function checkConstructor(func, name) { |
| 50 // A constructor is a function with a prototype and properties on the | 63 // A constructor is a function with a prototype and properties on the |
| 51 // prototype object besides "constructor"; | 64 // prototype object besides "constructor"; |
| 52 if (name.charAt(0) == "$") return; | 65 if (name.charAt(0) == "$") return; |
| 53 if (typeof func.prototype != "object") return; | 66 if (typeof func.prototype != "object") return; |
| 54 var propNames = Object.getOwnPropertyNames(func.prototype); | 67 var propNames = Object.getOwnPropertyNames(func.prototype); |
| 55 if (propNames.length == 0 || | 68 if (propNames.length == 0 || |
| 56 (propNames.length == 1 && propNames[0] == "constructor")) { | 69 (propNames.length == 1 && propNames[0] == "constructor")) { |
| 57 // Not a constructor. | 70 // Not a constructor. |
| 58 return; | 71 return; |
| 59 } | 72 } |
| 60 var proto_desc = Object.getOwnPropertyDescriptor(func, "prototype"); | 73 var proto_desc = Object.getOwnPropertyDescriptor(func, "prototype"); |
| 61 assertTrue(proto_desc.hasOwnProperty("value"), name); | 74 assertTrue(proto_desc.hasOwnProperty("value"), name); |
| 62 assertFalse(proto_desc.writable, name); | 75 assertFalse(proto_desc.writable, name); |
| 63 assertFalse(proto_desc.configurable, name); | 76 assertFalse(proto_desc.configurable, name); |
| 64 var prototype = proto_desc.value; | 77 var prototype = proto_desc.value; |
| 65 assertEquals(isV8Native(name) ? Object.prototype : null, | 78 assertEquals(V8NativePrototypes[name] || null, |
| 66 Object.getPrototypeOf(prototype), | 79 Object.getPrototypeOf(prototype), |
| 67 name); | 80 name); |
| 68 for (var i = 0; i < propNames.length; i++) { | 81 for (var i = 0; i < propNames.length; i++) { |
| 69 var propName = propNames[i]; | 82 var propName = propNames[i]; |
| 70 if (propName == "constructor") continue; | 83 if (propName == "constructor") continue; |
| 71 if (isV8Native(name)) continue; | 84 if (isV8Native(name)) continue; |
| 72 var testName = name + "-" + propName; | 85 var testName = name + "-" + propName; |
| 73 var propDesc = Object.getOwnPropertyDescriptor(prototype, propName); | 86 var propDesc = Object.getOwnPropertyDescriptor(prototype, propName); |
| 74 assertTrue(propDesc.hasOwnProperty("value"), testName); | 87 assertTrue(propDesc.hasOwnProperty("value"), testName); |
| 75 assertFalse(propDesc.configurable, testName); | 88 assertFalse(propDesc.configurable, testName); |
| 76 if (isFunction(propDesc.value)) { | 89 if (isFunction(propDesc.value)) { |
| 77 assertFalse(propDesc.writable, testName); | 90 assertFalse(propDesc.writable, testName); |
| 78 } | 91 } |
| 79 } | 92 } |
| 80 } | 93 } |
| 81 | 94 |
| 82 for (var i = 0; i < names.length; i++) { | 95 for (var i = 0; i < names.length; i++) { |
| 83 var name = names[i]; | 96 var name = names[i]; |
| 84 var desc = Object.getOwnPropertyDescriptor(builtins, name); | 97 var desc = Object.getOwnPropertyDescriptor(builtins, name); |
| 85 assertTrue(desc.hasOwnProperty("value")); | 98 assertTrue(desc.hasOwnProperty("value")); |
| 86 var value = desc.value; | 99 var value = desc.value; |
| 87 if (isFunction(value)) { | 100 if (isFunction(value)) { |
| 88 checkConstructor(value, name); | 101 checkConstructor(value, name); |
| 89 } | 102 } |
| 90 } | 103 } |
| OLD | NEW |