OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // MODULE |
| 6 |
| 7 let ja = 42; |
| 8 export {ja as yo}; |
| 9 export const bla = "blaa"; |
| 10 export {foo as foo_again}; |
| 11 // See further below for the actual star import that declares "foo". |
| 12 |
| 13 // The object itself. |
| 14 assertEquals("object", typeof foo); |
| 15 assertThrows(() => foo = 666, TypeError); |
| 16 assertFalse(Reflect.isExtensible(foo)); |
| 17 assertTrue(Reflect.preventExtensions(foo)); |
| 18 assertThrows(() => Reflect.apply(foo, {}, [])); |
| 19 assertThrows(() => Reflect.construct(foo, {}, [])); |
| 20 assertSame(null, Reflect.getPrototypeOf(foo)); |
| 21 // TODO(neis): The next one should be False. |
| 22 assertTrue(Reflect.setPrototypeOf(foo, null)); |
| 23 assertFalse(Reflect.setPrototypeOf(foo, {})); |
| 24 assertSame(null, Reflect.getPrototypeOf(foo)); |
| 25 // TODO(neis): The next one should include @@iterator at the end. |
| 26 assertEquals( |
| 27 ["bla", "foo_again", "yo", Symbol.toStringTag], |
| 28 Reflect.ownKeys(foo)); |
| 29 |
| 30 // Its "yo" property. |
| 31 assertEquals( |
| 32 {value: 42, enumerable: true, configurable: false, writable: true}, |
| 33 Reflect.getOwnPropertyDescriptor(foo, "yo")); |
| 34 assertFalse(Reflect.deleteProperty(foo, "yo")); |
| 35 assertTrue(Reflect.has(foo, "yo")); |
| 36 // TODO(neis): The next three should be False. |
| 37 assertTrue(Reflect.set(foo, "yo", true)); |
| 38 assertTrue(Reflect.defineProperty(foo, "yo", |
| 39 Reflect.getOwnPropertyDescriptor(foo, "yo"))); |
| 40 assertTrue(Reflect.defineProperty(foo, "yo", {})); |
| 41 assertFalse(Reflect.defineProperty(foo, "yo", {get() {return 1}})); |
| 42 assertEquals(42, Reflect.get(foo, "yo")); |
| 43 assertEquals(43, (ja++, foo.yo)); |
| 44 |
| 45 // Its "foo_again" property. |
| 46 assertSame(foo, foo.foo_again); |
| 47 |
| 48 // Its @@toStringTag property. |
| 49 assertTrue(Reflect.has(foo, Symbol.toStringTag)); |
| 50 assertEquals("string", typeof Reflect.get(foo, Symbol.toStringTag)); |
| 51 assertEquals( |
| 52 {value: "Module", configurable: true, writable: false, enumerable: false}, |
| 53 Reflect.getOwnPropertyDescriptor(foo, Symbol.toStringTag)); |
| 54 |
| 55 // TODO(neis): Its @@iterator property. |
| 56 // assertTrue(Reflect.has(foo, Symbol.iterator)); |
| 57 // assertEquals("function", typeof Reflect.get(foo, Symbol.iterator)); |
| 58 // assertEquals(["bla", "yo"], [...foo]); |
| 59 // assertThrows(() => (42, foo[Symbol.iterator])(), TypeError); |
| 60 // assertSame(foo[Symbol.iterator]().__proto__, |
| 61 // ([][Symbol.iterator]()).__proto__.__proto__); |
| 62 |
| 63 // TODO(neis): Clarify spec w.r.t. other symbols. |
| 64 |
| 65 // Nonexistant properties. |
| 66 let nonexistant = ["gaga", 123, Symbol('')]; |
| 67 for (let key of nonexistant) { |
| 68 assertSame(undefined, Reflect.getOwnPropertyDescriptor(foo, key)); |
| 69 assertTrue(Reflect.deleteProperty(foo, key)); |
| 70 assertFalse(Reflect.set(foo, key, true)); |
| 71 assertSame(undefined, Reflect.get(foo, key)); |
| 72 assertFalse(Reflect.defineProperty(foo, key, {get() {return 1}})); |
| 73 assertFalse(Reflect.has(foo, key)); |
| 74 } |
| 75 |
| 76 // The actual star import that we are testing. Namespace imports are |
| 77 // initialized before evaluation |
| 78 import * as foo from "modules-namespace1.js"; |
| 79 |
| 80 // There can be only one namespace object. |
| 81 import * as bar from "modules-namespace1.js"; |
| 82 assertSame(foo, bar); |
OLD | NEW |