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

Side by Side Diff: test/mjsunit/builtins.js

Issue 1062633002: Re-implement %Generator% intrinsic as an object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add TODO contact and bug URL Created 5 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
« no previous file with comments | « src/generator.js ('k') | test/mjsunit/es6/generators-runtime.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 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
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(jugglinmike): Update the following values to the %IteratorPrototype%
52 // intrinsic once it is implemented.
53 // Issue 3568: Generator Prototype should have an object between itself
54 // and Object.prototype
55 // https://code.google.com/p/v8/issues/detail?id=3568
56 GeneratorFunctionPrototype: Object.prototype,
57 SetIterator: Object.prototype,
58 MapIterator: Object.prototype,
59 ArrayIterator: Object.prototype,
60 StringIterator: Object.prototype
61 };
48 62
49 function checkConstructor(func, name) { 63 function checkConstructor(func, name) {
50 // A constructor is a function with a prototype and properties on the 64 // A constructor is a function with a prototype and properties on the
51 // prototype object besides "constructor"; 65 // prototype object besides "constructor";
52 if (name.charAt(0) == "$") return; 66 if (name.charAt(0) == "$") return;
53 if (typeof func.prototype != "object") return; 67 if (typeof func.prototype != "object") return;
54 var propNames = Object.getOwnPropertyNames(func.prototype); 68 var propNames = Object.getOwnPropertyNames(func.prototype);
55 if (propNames.length == 0 || 69 if (propNames.length == 0 ||
56 (propNames.length == 1 && propNames[0] == "constructor")) { 70 (propNames.length == 1 && propNames[0] == "constructor")) {
57 // Not a constructor. 71 // Not a constructor.
58 return; 72 return;
59 } 73 }
60 var proto_desc = Object.getOwnPropertyDescriptor(func, "prototype"); 74 var proto_desc = Object.getOwnPropertyDescriptor(func, "prototype");
61 assertTrue(proto_desc.hasOwnProperty("value"), name); 75 assertTrue(proto_desc.hasOwnProperty("value"), name);
62 assertFalse(proto_desc.writable, name); 76 assertFalse(proto_desc.writable, name);
63 assertFalse(proto_desc.configurable, name); 77 assertFalse(proto_desc.configurable, name);
64 var prototype = proto_desc.value; 78 var prototype = proto_desc.value;
65 assertEquals(isV8Native(name) ? Object.prototype : null, 79 assertEquals(V8NativePrototypes[name] || null,
66 Object.getPrototypeOf(prototype), 80 Object.getPrototypeOf(prototype),
67 name); 81 name);
68 for (var i = 0; i < propNames.length; i++) { 82 for (var i = 0; i < propNames.length; i++) {
69 var propName = propNames[i]; 83 var propName = propNames[i];
70 if (propName == "constructor") continue; 84 if (propName == "constructor") continue;
71 if (isV8Native(name)) continue; 85 if (isV8Native(name)) continue;
72 var testName = name + "-" + propName; 86 var testName = name + "-" + propName;
73 var propDesc = Object.getOwnPropertyDescriptor(prototype, propName); 87 var propDesc = Object.getOwnPropertyDescriptor(prototype, propName);
74 assertTrue(propDesc.hasOwnProperty("value"), testName); 88 assertTrue(propDesc.hasOwnProperty("value"), testName);
75 assertFalse(propDesc.configurable, testName); 89 assertFalse(propDesc.configurable, testName);
76 if (isFunction(propDesc.value)) { 90 if (isFunction(propDesc.value)) {
77 assertFalse(propDesc.writable, testName); 91 assertFalse(propDesc.writable, testName);
78 } 92 }
79 } 93 }
80 } 94 }
81 95
82 for (var i = 0; i < names.length; i++) { 96 for (var i = 0; i < names.length; i++) {
83 var name = names[i]; 97 var name = names[i];
84 var desc = Object.getOwnPropertyDescriptor(builtins, name); 98 var desc = Object.getOwnPropertyDescriptor(builtins, name);
85 assertTrue(desc.hasOwnProperty("value")); 99 assertTrue(desc.hasOwnProperty("value"));
86 var value = desc.value; 100 var value = desc.value;
87 if (isFunction(value)) { 101 if (isFunction(value)) {
88 checkConstructor(value, name); 102 checkConstructor(value, name);
89 } 103 }
90 } 104 }
OLDNEW
« no previous file with comments | « src/generator.js ('k') | test/mjsunit/es6/generators-runtime.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698