| OLD | NEW |
| 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 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
| 6 | 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); | 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); | 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 | 9 |
| 10 function testAddGetter(object, name, val) { | 10 function testAddGetter(object, name, val) { |
| 11 Object.defineProperty(object, name, { get: function() { return val; } }); | 11 Object.defineProperty(object, name, { get: function() { return val; } }); |
| 12 assertSame(val, object[name]); | 12 assertSame(val, object[name]); |
| 13 } | 13 } |
| 14 | 14 |
| 15 function testAddGetterFails(object, name, val) { |
| 16 function assign() { |
| 17 Object.defineProperty(object, name, { get: function() { return val; } }); |
| 18 } |
| 19 assertThrows(assign, TypeError); |
| 20 } |
| 21 |
| 15 function testAddGetterBothWays(object, name, val) { | 22 function testAddGetterBothWays(object, name, val) { |
| 16 print("Object.defineProperty"); | 23 print("Object.defineProperty"); |
| 17 Object.defineProperty(object, name, { get: function() { return val; } }); | 24 Object.defineProperty(object, name, { get: function() { return val; } }); |
| 18 print("object.__defineGetter__"); | 25 print("object.__defineGetter__"); |
| 19 object.__defineGetter__(name, () => val); | 26 object.__defineGetter__(name, () => val); |
| 20 assertSame(val, object[name]); | 27 assertSame(val, object[name]); |
| 21 } | 28 } |
| 22 | 29 |
| 23 function testFailToAddGetter(object, name, val) { | 30 function testFailToAddGetter(object, name, val) { |
| 24 assertThrows(() => Object.defineProperty(object, name, { get: function() { ret
urn val; } })); | 31 assertThrows(() => Object.defineProperty(object, name, { get: function() { ret
urn val; } })); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 var instance = builder.instantiate(); | 64 var instance = builder.instantiate(); |
| 58 testAddGetter(instance, "exports", 290); | 65 testAddGetter(instance, "exports", 290); |
| 59 testAddGetter(instance, "xyz", new Object()); | 66 testAddGetter(instance, "xyz", new Object()); |
| 60 })(); | 67 })(); |
| 61 | 68 |
| 62 (function TestAddGetterToExports() { | 69 (function TestAddGetterToExports() { |
| 63 print("TestAddGetterToExports..."); | 70 print("TestAddGetterToExports..."); |
| 64 var builder = makeBuilder(); | 71 var builder = makeBuilder(); |
| 65 var exports = builder.instantiate().exports; | 72 var exports = builder.instantiate().exports; |
| 66 testFailToAddGetter(exports, "f", 9834); | 73 testFailToAddGetter(exports, "f", 9834); |
| 67 testAddGetter(exports, "nag", new Number(2)); | 74 testAddGetterFails(exports, "nag", new Number(2)); |
| 68 })(); | 75 })(); |
| OLD | NEW |