OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 (function (global, binding) { | 5 (function (global, binding, v8) { |
6 'use strict'; | 6 'use strict'; |
7 binding.testExtraShouldReturnFive = function () { | 7 binding.testExtraShouldReturnFive = function() { |
8 return 5; | 8 return 5; |
9 }; | 9 }; |
10 | 10 |
11 binding.testExtraShouldCallToRuntime = function() { | 11 binding.testExtraShouldCallToRuntime = function() { |
12 return binding.runtime(3); | 12 return binding.runtime(3); |
13 }; | 13 }; |
| 14 |
| 15 // Exercise all of the extras utils: |
| 16 // - v8.createPrivateSymbol |
| 17 // - v8.simpleBind, v8.uncurryThis |
| 18 // - v8.InternalPackedArray |
| 19 // - v8.createPromise, v8.resolvePromise, v8.rejectPromise |
| 20 |
| 21 const Object = global.Object; |
| 22 const hasOwn = v8.uncurryThis(Object.prototype.hasOwnProperty); |
| 23 |
| 24 const Function = global.Function; |
| 25 const call = v8.uncurryThis(Function.prototype.call); |
| 26 const apply = v8.uncurryThis(Function.prototype.apply); |
| 27 |
| 28 const Promise = global.Promise; |
| 29 const Promise_resolve = v8.simpleBind(Promise.resolve, Promise); |
| 30 |
| 31 binding.testExtraCanUseUtils = function() { |
| 32 const fulfilledPromise = v8.createPromise(); |
| 33 v8.resolvePromise( |
| 34 fulfilledPromise, |
| 35 hasOwn({ test: 'test' }, 'test') ? 1 : -1 |
| 36 ); |
| 37 |
| 38 const fulfilledPromise2 = Promise_resolve(call(function (arg1) { |
| 39 return (this.prop === arg1 && arg1 === 'value') ? 2 : -1; |
| 40 }, { prop: 'value' }, 'value')); |
| 41 |
| 42 const rejectedPromise = v8.createPromise(); |
| 43 v8.rejectPromise(rejectedPromise, apply(function (arg1, arg2) { |
| 44 return (arg1 === arg2 && arg2 === 'x') ? 3 : -1; |
| 45 }, null, new v8.InternalPackedArray('x', 'x'))); |
| 46 |
| 47 return { |
| 48 privateSymbol: v8.createPrivateSymbol('sym'), |
| 49 fulfilledPromise, // should be fulfilled with 1 |
| 50 fulfilledPromise2, // should be fulfilled with 2 |
| 51 rejectedPromise // should be rejected with 3 |
| 52 }; |
| 53 }; |
14 }) | 54 }) |
OLD | NEW |