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

Side by Side Diff: test/mjsunit/modules-namespace1.js

Issue 2407423002: [modules] Implement @@iterator on namespace objects. (Closed)
Patch Set: Rename kSize to kHeadersize again. Created 4 years, 2 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // MODULE 5 // MODULE
6 6
7 let ja = 42; 7 let ja = 42;
8 export {ja as yo}; 8 export {ja as yo};
9 export const bla = "blaa"; 9 export const bla = "blaa";
10 export {foo as foo_again}; 10 export {foo as foo_again};
11 // See further below for the actual star import that declares "foo". 11 // See further below for the actual star import that declares "foo".
12 12
13 // The object itself. 13 // The object itself.
14 assertEquals("object", typeof foo); 14 assertEquals("object", typeof foo);
15 assertThrows(() => foo = 666, TypeError); 15 assertThrows(() => foo = 666, TypeError);
16 assertFalse(Reflect.isExtensible(foo)); 16 assertFalse(Reflect.isExtensible(foo));
17 assertTrue(Reflect.preventExtensions(foo)); 17 assertTrue(Reflect.preventExtensions(foo));
18 assertThrows(() => Reflect.apply(foo, {}, [])); 18 assertThrows(() => Reflect.apply(foo, {}, []));
19 assertThrows(() => Reflect.construct(foo, {}, [])); 19 assertThrows(() => Reflect.construct(foo, {}, []));
20 assertSame(null, Reflect.getPrototypeOf(foo)); 20 assertSame(null, Reflect.getPrototypeOf(foo));
21 // TODO(neis): The next one should be False. 21 // TODO(neis): The next one should be False.
22 assertTrue(Reflect.setPrototypeOf(foo, null)); 22 assertTrue(Reflect.setPrototypeOf(foo, null));
23 assertFalse(Reflect.setPrototypeOf(foo, {})); 23 assertFalse(Reflect.setPrototypeOf(foo, {}));
24 assertSame(null, Reflect.getPrototypeOf(foo)); 24 assertSame(null, Reflect.getPrototypeOf(foo));
25 // TODO(neis): The next one should include @@iterator at the end.
26 assertEquals( 25 assertEquals(
27 ["bla", "foo_again", "yo", Symbol.toStringTag], 26 ["bla", "foo_again", "yo", Symbol.toStringTag, Symbol.iterator],
28 Reflect.ownKeys(foo)); 27 Reflect.ownKeys(foo));
29 28
30 // Its "yo" property. 29 // Its "yo" property.
31 assertEquals( 30 assertEquals(
32 {value: 42, enumerable: true, configurable: false, writable: true}, 31 {value: 42, enumerable: true, configurable: false, writable: true},
33 Reflect.getOwnPropertyDescriptor(foo, "yo")); 32 Reflect.getOwnPropertyDescriptor(foo, "yo"));
34 assertFalse(Reflect.deleteProperty(foo, "yo")); 33 assertFalse(Reflect.deleteProperty(foo, "yo"));
35 assertTrue(Reflect.has(foo, "yo")); 34 assertTrue(Reflect.has(foo, "yo"));
36 // TODO(neis): The next three should be False. 35 // TODO(neis): The next three should be False.
37 assertTrue(Reflect.set(foo, "yo", true)); 36 assertTrue(Reflect.set(foo, "yo", true));
38 assertTrue(Reflect.defineProperty(foo, "yo", 37 assertTrue(Reflect.defineProperty(foo, "yo",
39 Reflect.getOwnPropertyDescriptor(foo, "yo"))); 38 Reflect.getOwnPropertyDescriptor(foo, "yo")));
40 assertTrue(Reflect.defineProperty(foo, "yo", {})); 39 assertTrue(Reflect.defineProperty(foo, "yo", {}));
41 assertFalse(Reflect.defineProperty(foo, "yo", {get() {return 1}})); 40 assertFalse(Reflect.defineProperty(foo, "yo", {get() {return 1}}));
42 assertEquals(42, Reflect.get(foo, "yo")); 41 assertEquals(42, Reflect.get(foo, "yo"));
43 assertEquals(43, (ja++, foo.yo)); 42 assertEquals(43, (ja++, foo.yo));
44 43
45 // Its "foo_again" property. 44 // Its "foo_again" property.
46 assertSame(foo, foo.foo_again); 45 assertSame(foo, foo.foo_again);
47 46
48 // Its @@toStringTag property. 47 // Its @@toStringTag property.
49 assertTrue(Reflect.has(foo, Symbol.toStringTag)); 48 assertTrue(Reflect.has(foo, Symbol.toStringTag));
50 assertEquals("string", typeof Reflect.get(foo, Symbol.toStringTag)); 49 assertEquals("string", typeof Reflect.get(foo, Symbol.toStringTag));
51 assertEquals( 50 assertEquals(
52 {value: "Module", configurable: true, writable: false, enumerable: false}, 51 {value: "Module", configurable: true, writable: false, enumerable: false},
53 Reflect.getOwnPropertyDescriptor(foo, Symbol.toStringTag)); 52 Reflect.getOwnPropertyDescriptor(foo, Symbol.toStringTag));
54 53
55 // TODO(neis): Its @@iterator property. 54 // Its @@iterator property.
56 // assertTrue(Reflect.has(foo, Symbol.iterator)); 55 assertTrue(Reflect.has(foo, Symbol.iterator));
57 // assertEquals("function", typeof Reflect.get(foo, Symbol.iterator)); 56 assertEquals("function", typeof Reflect.get(foo, Symbol.iterator));
58 // assertEquals(["bla", "yo"], [...foo]); 57 assertEquals("[Symbol.iterator]", foo[Symbol.iterator].name);
59 // assertThrows(() => (42, foo[Symbol.iterator])(), TypeError); 58 assertEquals(0, foo[Symbol.iterator].length);
60 // assertSame(foo[Symbol.iterator]().__proto__, 59 assertSame(Function.prototype, foo[Symbol.iterator].__proto__);
61 // ([][Symbol.iterator]()).__proto__.__proto__); 60 assertEquals(
61 {value: foo[Symbol.iterator],
62 configurable: true, writable: true, enumerable: false},
63 Reflect.getOwnPropertyDescriptor(foo, Symbol.iterator));
64 assertEquals(["bla", "foo_again", "yo"], [...foo]);
65 assertThrows(() => (42, foo[Symbol.iterator])(), TypeError);
66 {
67 let it = foo[Symbol.iterator]();
68 assertSame(it.__proto__, ([][Symbol.iterator]()).__proto__.__proto__);
69 assertEquals(["next"], Reflect.ownKeys(it));
70 assertEquals(
71 {value: it.next, configurable: true, writable: true, enumerable: false},
72 Reflect.getOwnPropertyDescriptor(it, "next"));
73 assertEquals("function", typeof it.next);
74 assertEquals("next", it.next.name);
75 assertEquals(0, it.next.length);
76 assertSame(Function.prototype, it.next.__proto__);
77 assertFalse(it === foo[Symbol.iterator]());
78 assertFalse(it.next === foo[Symbol.iterator]().next);
79 assertThrows(() => (42, it.next)(), TypeError);
80 assertThrows(() => it.next.call(foo[Symbol.iterator]()), TypeError);
81 let next = it.next;
82 assertEquals(42, (it.next = 42, it.next));
83 assertEquals(43, (it.bla = 43, it.bla));
84 assertTrue(delete it.next);
85 assertThrows(() => next.call(foo[Symbol.iterator]()), TypeError);
86 }
62 87
63 // TODO(neis): Clarify spec w.r.t. other symbols. 88 // TODO(neis): Clarify spec w.r.t. other symbols.
64 89
65 // Nonexistant properties. 90 // Nonexistant properties.
66 let nonexistant = ["gaga", 123, Symbol('')]; 91 let nonexistant = ["gaga", 123, Symbol('')];
67 for (let key of nonexistant) { 92 for (let key of nonexistant) {
68 assertSame(undefined, Reflect.getOwnPropertyDescriptor(foo, key)); 93 assertSame(undefined, Reflect.getOwnPropertyDescriptor(foo, key));
69 assertTrue(Reflect.deleteProperty(foo, key)); 94 assertTrue(Reflect.deleteProperty(foo, key));
70 assertFalse(Reflect.set(foo, key, true)); 95 assertFalse(Reflect.set(foo, key, true));
71 assertSame(undefined, Reflect.get(foo, key)); 96 assertSame(undefined, Reflect.get(foo, key));
72 assertFalse(Reflect.defineProperty(foo, key, {get() {return 1}})); 97 assertFalse(Reflect.defineProperty(foo, key, {get() {return 1}}));
73 assertFalse(Reflect.has(foo, key)); 98 assertFalse(Reflect.has(foo, key));
74 } 99 }
75 100
76 // The actual star import that we are testing. Namespace imports are 101 // The actual star import that we are testing. Namespace imports are
77 // initialized before evaluation 102 // initialized before evaluation.
78 import * as foo from "modules-namespace1.js"; 103 import * as foo from "modules-namespace1.js";
79 104
80 // There can be only one namespace object. 105 // There can be only one namespace object.
81 import * as bar from "modules-namespace1.js"; 106 import * as bar from "modules-namespace1.js";
82 assertSame(foo, bar); 107 assertSame(foo, bar);
OLDNEW
« no previous file with comments | « test/cctest/interpreter/bytecode_expectations/CallRuntime.golden ('k') | test/mjsunit/modules-namespace2.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698