2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 function call(thisArgument)
30 let argumentValues = [];
31 // Start from 1 to ignore thisArgument
32 for (let i = 1; i < arguments.length; i++)
33 @putByValDirect(argumentValues, i-1, arguments[i]);
35 return this.@apply(thisArgument, argumentValues);
38 function apply(thisValue, argumentValues)
42 return this.@apply(thisValue, argumentValues);
45 // FIXME: this should have a different name: https://bugs.webkit.org/show_bug.cgi?id=151363
46 function symbolHasInstance(value)
50 if (typeof this !== "function")
53 if (@isBoundFunction(this))
54 return @hasInstanceBoundFunction(this, value);
56 let target = this.prototype;
57 return @instanceOf(value, target);
60 function bind(thisValue)
65 if (typeof target !== "function")
66 @throwTypeError("|this| is not a function inside Function.prototype.bind");
68 let argumentCount = arguments.length;
71 if (argumentCount > 1) {
72 numBoundArgs = argumentCount - 1;
73 boundArgs = @newArrayWithSize(numBoundArgs);
74 for (let i = 0; i < numBoundArgs; i++)
75 @putByValDirect(boundArgs, i, arguments[i + 1]);
79 if (@hasOwnLengthProperty(target)) {
80 let lengthValue = target.length;
81 if (typeof lengthValue === "number") {
82 lengthValue = lengthValue | 0;
83 // Note that we only care about positive lengthValues, however, this comparision
84 // against numBoundArgs suffices to prove we're not a negative number.
85 if (lengthValue > numBoundArgs)
86 length = lengthValue - numBoundArgs;
90 let name = target.name;
91 if (typeof name !== "string")
94 return @makeBoundFunction(target, arguments[0], boundArgs, length, name);