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 // Flags: --expose-wasm |
| 6 |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); |
| 9 |
| 10 function testAddGetter(object, name, val) { |
| 11 Object.defineProperty(object, name, { get: function() { return val; } }); |
| 12 assertSame(val, object[name]); |
| 13 } |
| 14 |
| 15 function testAddGetterBothWays(object, name, val) { |
| 16 print("Object.defineProperty"); |
| 17 Object.defineProperty(object, name, { get: function() { return val; } }); |
| 18 print("object.__defineGetter__"); |
| 19 object.__defineGetter__(name, () => val); |
| 20 assertSame(val, object[name]); |
| 21 } |
| 22 |
| 23 function testFailToAddGetter(object, name, val) { |
| 24 assertThrows(() => Object.defineProperty(object, name, { get: function() { ret
urn val; } })); |
| 25 } |
| 26 |
| 27 testAddGetter(testAddGetter, "name", 11); |
| 28 |
| 29 function makeBuilder() { |
| 30 var builder = new WasmModuleBuilder(); |
| 31 |
| 32 builder.addFunction("f", kSig_v_v) |
| 33 .addBody([]) |
| 34 .exportFunc(); |
| 35 return builder; |
| 36 } |
| 37 |
| 38 (function TestAddGetterToFunction() { |
| 39 print("TestAddGetterToFunction..."); |
| 40 var builder = makeBuilder(); |
| 41 var f = builder.instantiate().exports.f; |
| 42 testAddGetterBothWays(f, "name", "foo"); |
| 43 testAddGetter(f, "blam", "baz"); |
| 44 })(); |
| 45 |
| 46 (function TestAddGetterToModule() { |
| 47 print("TestAddGetterToModule..."); |
| 48 var builder = makeBuilder(); |
| 49 var module = new WebAssembly.Module(builder.toBuffer()); |
| 50 testAddGetter(module, "exports", 290); |
| 51 testAddGetter(module, "xyz", new Object()); |
| 52 })(); |
| 53 |
| 54 (function TestAddGetterToInstance() { |
| 55 print("TestAddGetterToInstance..."); |
| 56 var builder = makeBuilder(); |
| 57 var instance = builder.instantiate(); |
| 58 testAddGetter(instance, "exports", 290); |
| 59 testAddGetter(instance, "xyz", new Object()); |
| 60 })(); |
| 61 |
| 62 (function TestAddGetterToExports() { |
| 63 print("TestAddGetterToExports..."); |
| 64 var builder = makeBuilder(); |
| 65 var exports = builder.instantiate().exports; |
| 66 testFailToAddGetter(exports, "f", 9834); |
| 67 testAddGetter(exports, "nag", new Number(2)); |
| 68 })(); |
OLD | NEW |