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 3// found in the LICENSE file. 4 5(function (global, binding, v8) { 6 'use strict'; 7 binding.testExtraShouldReturnFive = function() { 8 return 5; 9 }; 10 11 binding.testExtraShouldCallToRuntime = function() { 12 return binding.runtime(3); 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 const arrayToTest = new v8.InternalPackedArray(); 32 arrayToTest.push(1); 33 arrayToTest.push(2); 34 arrayToTest.pop(); 35 arrayToTest.unshift("a", "b", "c"); 36 arrayToTest.shift(); 37 arrayToTest.splice(0, 1); 38 const slicedArray = arrayToTest.slice(); 39 const arraysOK = arrayToTest.length === 2 && arrayToTest[0] === "c" && 40 arrayToTest[1] === 1 && slicedArray.length === 2 && 41 slicedArray[0] === "c" && slicedArray[1] === 1; 42 43 binding.testExtraCanUseUtils = function() { 44 const fulfilledPromise = v8.createPromise(); 45 v8.resolvePromise( 46 fulfilledPromise, 47 hasOwn({ test: 'test' }, 'test') ? 1 : -1 48 ); 49 50 const fulfilledPromise2 = Promise_resolve(call(function (arg1, arg2) { 51 return (this.prop === arg1 && arg1 === 'value' && arg2) ? 2 : -1; 52 }, { prop: 'value' }, 'value', arraysOK)); 53 54 const rejectedPromise = v8.createPromise(); 55 v8.rejectPromise(rejectedPromise, apply(function (arg1, arg2) { 56 return (arg1 === arg2 && arg2 === 'x') ? 3 : -1; 57 }, null, new v8.InternalPackedArray('x', 'x'))); 58 59 return { 60 privateSymbol: v8.createPrivateSymbol('sym'), 61 fulfilledPromise, // should be fulfilled with 1 62 fulfilledPromise2, // should be fulfilled with 2 63 rejectedPromise // should be rejected with 3 64 }; 65 }; 66}) 67