erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 28 | // This file relies on the fact that the following declarations have been made |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 29 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 30 | // in runtime.js: |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 31 | // var $Object = global.Object; |
| 32 | // var $Boolean = global.Boolean; |
| 33 | // var $Number = global.Number; |
| 34 | // var $Function = global.Function; |
| 35 | // var $Array = global.Array; |
| 36 | // var $NaN = 0/0; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 37 | // |
| 38 | // in math.js: |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 39 | // var $floor = MathFloor |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 40 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 41 | var $isNaN = GlobalIsNaN; |
| 42 | var $isFinite = GlobalIsFinite; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 43 | |
| 44 | // ---------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 45 | |
| 46 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 47 | // Helper function used to install functions on objects. |
| 48 | function InstallFunctions(object, attributes, functions) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 49 | if (functions.length >= 8) { |
| 50 | %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); |
| 51 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 52 | for (var i = 0; i < functions.length; i += 2) { |
| 53 | var key = functions[i]; |
| 54 | var f = functions[i + 1]; |
| 55 | %FunctionSetName(f, key); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 56 | %FunctionRemovePrototype(f); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 57 | %SetProperty(object, key, f, attributes); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 58 | %SetNativeFlag(f); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 59 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 60 | %ToFastProperties(object); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 61 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 62 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 63 | |
| 64 | // Helper function to install a getter only property. |
| 65 | function InstallGetter(object, name, getter) { |
| 66 | %FunctionSetName(getter, name); |
| 67 | %FunctionRemovePrototype(getter); |
| 68 | %DefineOrRedefineAccessorProperty(object, name, getter, null, DONT_ENUM); |
| 69 | %SetNativeFlag(getter); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | // Prevents changes to the prototype of a built-in function. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 74 | // The "prototype" property of the function object is made non-configurable, |
| 75 | // and the prototype object is made non-extensible. The latter prevents |
| 76 | // changing the __proto__ property. |
| 77 | function SetUpLockedPrototype(constructor, fields, methods) { |
| 78 | %CheckIsBootstrapping(); |
| 79 | var prototype = constructor.prototype; |
| 80 | // Install functions first, because this function is used to initialize |
| 81 | // PropertyDescriptor itself. |
| 82 | var property_count = (methods.length >> 1) + (fields ? fields.length : 0); |
| 83 | if (property_count >= 4) { |
| 84 | %OptimizeObjectForAddingMultipleProperties(prototype, property_count); |
| 85 | } |
| 86 | if (fields) { |
| 87 | for (var i = 0; i < fields.length; i++) { |
| 88 | %SetProperty(prototype, fields[i], void 0, DONT_ENUM | DONT_DELETE); |
| 89 | } |
| 90 | } |
| 91 | for (var i = 0; i < methods.length; i += 2) { |
| 92 | var key = methods[i]; |
| 93 | var f = methods[i + 1]; |
| 94 | %SetProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 95 | %SetNativeFlag(f); |
| 96 | } |
| 97 | prototype.__proto__ = null; |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 98 | %ToFastProperties(prototype); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 102 | // ---------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | |
| 104 | |
| 105 | // ECMA 262 - 15.1.4 |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 106 | function GlobalIsNaN(number) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 107 | if (!IS_NUMBER(number)) number = NonNumberToNumber(number); |
| 108 | return NUMBER_IS_NAN(number); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 109 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 110 | |
| 111 | |
| 112 | // ECMA 262 - 15.1.5 |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 113 | function GlobalIsFinite(number) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 114 | if (!IS_NUMBER(number)) number = NonNumberToNumber(number); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 115 | return NUMBER_IS_FINITE(number); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 116 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | |
| 118 | |
| 119 | // ECMA-262 - 15.1.2.2 |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 120 | function GlobalParseInt(string, radix) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 121 | if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | // Some people use parseInt instead of Math.floor. This |
| 123 | // optimization makes parseInt on a Smi 12 times faster (60ns |
| 124 | // vs 800ns). The following optimization makes parseInt on a |
| 125 | // non-Smi number 9 times faster (230ns vs 2070ns). Together |
| 126 | // they make parseInt on a string 1.4% slower (274ns vs 270ns). |
| 127 | if (%_IsSmi(string)) return string; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 128 | if (IS_NUMBER(string) && |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 129 | ((0.01 < string && string < 1e9) || |
| 130 | (-1e9 < string && string < -0.01))) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 131 | // Truncate number. |
| 132 | return string | 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | } |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 134 | string = TO_STRING_INLINE(string); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 135 | radix = radix | 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 136 | } else { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 137 | // The spec says ToString should be evaluated before ToInt32. |
| 138 | string = TO_STRING_INLINE(string); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | radix = TO_INT32(radix); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 140 | if (!(radix == 0 || (2 <= radix && radix <= 36))) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 141 | return $NaN; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 142 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | } |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 144 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 145 | if (%_HasCachedArrayIndex(string) && |
| 146 | (radix == 0 || radix == 10)) { |
| 147 | return %_GetCachedArrayIndex(string); |
| 148 | } |
| 149 | return %StringParseInt(string, radix); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 150 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 151 | |
| 152 | |
| 153 | // ECMA-262 - 15.1.2.3 |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 154 | function GlobalParseFloat(string) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 155 | string = TO_STRING_INLINE(string); |
| 156 | if (%_HasCachedArrayIndex(string)) return %_GetCachedArrayIndex(string); |
| 157 | return %StringParseFloat(string); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
| 161 | function GlobalEval(x) { |
| 162 | if (!IS_STRING(x)) return x; |
| 163 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 164 | var global_receiver = %GlobalReceiver(global); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 165 | var global_is_detached = (global === global_receiver); |
| 166 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 167 | // For consistency with JSC we require the global object passed to |
| 168 | // eval to be the global object from which 'eval' originated. This |
| 169 | // is not mandated by the spec. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 170 | // We only throw if the global has been detached, since we need the |
| 171 | // receiver as this-value for the call. |
| 172 | if (global_is_detached) { |
| 173 | throw new $EvalError('The "this" value passed to eval must ' + |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 174 | 'be the global object from which eval originated'); |
| 175 | } |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 176 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 177 | var f = %CompileString(x); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 178 | if (!IS_FUNCTION(f)) return f; |
| 179 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 180 | return %_CallFunction(global_receiver, f); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 184 | // ---------------------------------------------------------------------------- |
| 185 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 186 | // Set up global object. |
| 187 | function SetUpGlobal() { |
| 188 | %CheckIsBootstrapping(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 189 | // ECMA 262 - 15.1.1.1. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 190 | %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 191 | |
| 192 | // ECMA-262 - 15.1.1.2. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 193 | %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE | READ_ONLY); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 194 | |
| 195 | // ECMA-262 - 15.1.1.3. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 196 | %SetProperty(global, "undefined", void 0, |
| 197 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 198 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 199 | // Set up non-enumerable function on the global object. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 200 | InstallFunctions(global, DONT_ENUM, $Array( |
| 201 | "isNaN", GlobalIsNaN, |
| 202 | "isFinite", GlobalIsFinite, |
| 203 | "parseInt", GlobalParseInt, |
| 204 | "parseFloat", GlobalParseFloat, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 205 | "eval", GlobalEval |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 206 | )); |
| 207 | } |
| 208 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 209 | SetUpGlobal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 210 | |
| 211 | // ---------------------------------------------------------------------------- |
| 212 | // Boolean (first part of definition) |
| 213 | |
| 214 | |
| 215 | %SetCode($Boolean, function(x) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 216 | if (%_IsConstructCall()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 217 | %_SetValueOf(this, ToBoolean(x)); |
| 218 | } else { |
| 219 | return ToBoolean(x); |
| 220 | } |
| 221 | }); |
| 222 | |
| 223 | %FunctionSetPrototype($Boolean, new $Boolean(false)); |
| 224 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 225 | %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 226 | |
| 227 | // ---------------------------------------------------------------------------- |
| 228 | // Object |
| 229 | |
| 230 | $Object.prototype.constructor = $Object; |
| 231 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 232 | // ECMA-262 - 15.2.4.2 |
| 233 | function ObjectToString() { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame^] | 234 | if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
| 235 | if (IS_NULL(this)) return "[object Null]"; |
| 236 | if (IS_SYMBOL(this)) return "[object Symbol]"; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 237 | return "[object " + %_ClassOf(ToObject(this)) + "]"; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 238 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 239 | |
| 240 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 241 | // ECMA-262 - 15.2.4.3 |
| 242 | function ObjectToLocaleString() { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 243 | if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 244 | throw MakeTypeError("called_on_null_or_undefined", |
| 245 | ["Object.prototype.toLocaleString"]); |
| 246 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | return this.toString(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 248 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 249 | |
| 250 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 251 | // ECMA-262 - 15.2.4.4 |
| 252 | function ObjectValueOf() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 253 | return ToObject(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 254 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | |
| 256 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 257 | // ECMA-262 - 15.2.4.5 |
| 258 | function ObjectHasOwnProperty(V) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 259 | if (%IsJSProxy(this)) { |
| 260 | var handler = %GetHandler(this); |
| 261 | return CallTrap1(handler, "hasOwn", DerivedHasOwnTrap, TO_STRING_INLINE(V)); |
| 262 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 263 | return %HasLocalProperty(TO_OBJECT_INLINE(this), TO_STRING_INLINE(V)); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 264 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | |
| 266 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 267 | // ECMA-262 - 15.2.4.6 |
| 268 | function ObjectIsPrototypeOf(V) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 269 | if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
| 270 | throw MakeTypeError("called_on_null_or_undefined", |
| 271 | ["Object.prototype.isPrototypeOf"]); |
| 272 | } |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 273 | if (!IS_SPEC_OBJECT(V)) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 274 | return %IsInPrototypeChain(this, V); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 275 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | |
| 277 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 278 | // ECMA-262 - 15.2.4.6 |
| 279 | function ObjectPropertyIsEnumerable(V) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 280 | var P = ToString(V); |
| 281 | if (%IsJSProxy(this)) { |
| 282 | var desc = GetOwnProperty(this, P); |
| 283 | return IS_UNDEFINED(desc) ? false : desc.isEnumerable(); |
| 284 | } |
| 285 | return %IsPropertyEnumerable(ToObject(this), P); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 286 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 287 | |
| 288 | |
| 289 | // Extensions for providing property getters and setters. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 290 | function ObjectDefineGetter(name, fun) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 291 | var receiver = this; |
| 292 | if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
| 293 | receiver = %GlobalReceiver(global); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 294 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 295 | if (!IS_SPEC_FUNCTION(fun)) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 296 | throw new $TypeError( |
| 297 | 'Object.prototype.__defineGetter__: Expecting function'); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 298 | } |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 299 | var desc = new PropertyDescriptor(); |
| 300 | desc.setGet(fun); |
| 301 | desc.setEnumerable(true); |
| 302 | desc.setConfigurable(true); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 303 | DefineOwnProperty(ToObject(receiver), ToString(name), desc, false); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 304 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | |
| 306 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 307 | function ObjectLookupGetter(name) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 308 | var receiver = this; |
| 309 | if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
| 310 | receiver = %GlobalReceiver(global); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 311 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 312 | return %LookupAccessor(ToObject(receiver), ToString(name), GETTER); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 313 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | |
| 315 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 316 | function ObjectDefineSetter(name, fun) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 317 | var receiver = this; |
| 318 | if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
| 319 | receiver = %GlobalReceiver(global); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 320 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 321 | if (!IS_SPEC_FUNCTION(fun)) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 322 | throw new $TypeError( |
| 323 | 'Object.prototype.__defineSetter__: Expecting function'); |
| 324 | } |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 325 | var desc = new PropertyDescriptor(); |
| 326 | desc.setSet(fun); |
| 327 | desc.setEnumerable(true); |
| 328 | desc.setConfigurable(true); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 329 | DefineOwnProperty(ToObject(receiver), ToString(name), desc, false); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 330 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 331 | |
| 332 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 333 | function ObjectLookupSetter(name) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 334 | var receiver = this; |
| 335 | if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
| 336 | receiver = %GlobalReceiver(global); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 337 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 338 | return %LookupAccessor(ToObject(receiver), ToString(name), SETTER); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 339 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 340 | |
| 341 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 342 | function ObjectKeys(obj) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 343 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 344 | throw MakeTypeError("called_on_non_object", ["Object.keys"]); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 345 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 346 | if (%IsJSProxy(obj)) { |
| 347 | var handler = %GetHandler(obj); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 348 | var names = CallTrap0(handler, "keys", DerivedKeysTrap); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 349 | return ToStringArray(names, "keys"); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 350 | } |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 351 | return %LocalKeys(obj); |
| 352 | } |
| 353 | |
| 354 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 355 | // ES5 8.10.1. |
| 356 | function IsAccessorDescriptor(desc) { |
| 357 | if (IS_UNDEFINED(desc)) return false; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 358 | return desc.hasGetter() || desc.hasSetter(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | |
| 362 | // ES5 8.10.2. |
| 363 | function IsDataDescriptor(desc) { |
| 364 | if (IS_UNDEFINED(desc)) return false; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 365 | return desc.hasValue() || desc.hasWritable(); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | |
| 369 | // ES5 8.10.3. |
| 370 | function IsGenericDescriptor(desc) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 371 | if (IS_UNDEFINED(desc)) return false; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 372 | return !(IsAccessorDescriptor(desc) || IsDataDescriptor(desc)); |
| 373 | } |
| 374 | |
| 375 | |
| 376 | function IsInconsistentDescriptor(desc) { |
| 377 | return IsAccessorDescriptor(desc) && IsDataDescriptor(desc); |
| 378 | } |
| 379 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 380 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 381 | // ES5 8.10.4 |
| 382 | function FromPropertyDescriptor(desc) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 383 | if (IS_UNDEFINED(desc)) return desc; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 384 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 385 | if (IsDataDescriptor(desc)) { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 386 | return { value: desc.getValue(), |
| 387 | writable: desc.isWritable(), |
| 388 | enumerable: desc.isEnumerable(), |
| 389 | configurable: desc.isConfigurable() }; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 390 | } |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 391 | // Must be an AccessorDescriptor then. We never return a generic descriptor. |
| 392 | return { get: desc.getGet(), |
| 393 | set: desc.getSet(), |
| 394 | enumerable: desc.isEnumerable(), |
| 395 | configurable: desc.isConfigurable() }; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 396 | } |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 397 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 398 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 399 | // Harmony Proxies |
| 400 | function FromGenericPropertyDescriptor(desc) { |
| 401 | if (IS_UNDEFINED(desc)) return desc; |
| 402 | var obj = new $Object(); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 403 | |
| 404 | if (desc.hasValue()) { |
| 405 | %IgnoreAttributesAndSetProperty(obj, "value", desc.getValue(), NONE); |
| 406 | } |
| 407 | if (desc.hasWritable()) { |
| 408 | %IgnoreAttributesAndSetProperty(obj, "writable", desc.isWritable(), NONE); |
| 409 | } |
| 410 | if (desc.hasGetter()) { |
| 411 | %IgnoreAttributesAndSetProperty(obj, "get", desc.getGet(), NONE); |
| 412 | } |
| 413 | if (desc.hasSetter()) { |
| 414 | %IgnoreAttributesAndSetProperty(obj, "set", desc.getSet(), NONE); |
| 415 | } |
| 416 | if (desc.hasEnumerable()) { |
| 417 | %IgnoreAttributesAndSetProperty(obj, "enumerable", |
| 418 | desc.isEnumerable(), NONE); |
| 419 | } |
| 420 | if (desc.hasConfigurable()) { |
| 421 | %IgnoreAttributesAndSetProperty(obj, "configurable", |
| 422 | desc.isConfigurable(), NONE); |
| 423 | } |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 424 | return obj; |
| 425 | } |
| 426 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 427 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 428 | // ES5 8.10.5. |
| 429 | function ToPropertyDescriptor(obj) { |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 430 | if (!IS_SPEC_OBJECT(obj)) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 431 | throw MakeTypeError("property_desc_object", [obj]); |
| 432 | } |
| 433 | var desc = new PropertyDescriptor(); |
| 434 | |
| 435 | if ("enumerable" in obj) { |
| 436 | desc.setEnumerable(ToBoolean(obj.enumerable)); |
| 437 | } |
| 438 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 439 | if ("configurable" in obj) { |
| 440 | desc.setConfigurable(ToBoolean(obj.configurable)); |
| 441 | } |
| 442 | |
| 443 | if ("value" in obj) { |
| 444 | desc.setValue(obj.value); |
| 445 | } |
| 446 | |
| 447 | if ("writable" in obj) { |
| 448 | desc.setWritable(ToBoolean(obj.writable)); |
| 449 | } |
| 450 | |
| 451 | if ("get" in obj) { |
| 452 | var get = obj.get; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 453 | if (!IS_UNDEFINED(get) && !IS_SPEC_FUNCTION(get)) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 454 | throw MakeTypeError("getter_must_be_callable", [get]); |
| 455 | } |
| 456 | desc.setGet(get); |
| 457 | } |
| 458 | |
| 459 | if ("set" in obj) { |
| 460 | var set = obj.set; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 461 | if (!IS_UNDEFINED(set) && !IS_SPEC_FUNCTION(set)) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 462 | throw MakeTypeError("setter_must_be_callable", [set]); |
| 463 | } |
| 464 | desc.setSet(set); |
| 465 | } |
| 466 | |
| 467 | if (IsInconsistentDescriptor(desc)) { |
| 468 | throw MakeTypeError("value_and_accessor", [obj]); |
| 469 | } |
| 470 | return desc; |
| 471 | } |
| 472 | |
| 473 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 474 | // For Harmony proxies. |
| 475 | function ToCompletePropertyDescriptor(obj) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 476 | var desc = ToPropertyDescriptor(obj); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 477 | if (IsGenericDescriptor(desc) || IsDataDescriptor(desc)) { |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 478 | if (!desc.hasValue()) desc.setValue(void 0); |
| 479 | if (!desc.hasWritable()) desc.setWritable(false); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 480 | } else { |
| 481 | // Is accessor descriptor. |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 482 | if (!desc.hasGetter()) desc.setGet(void 0); |
| 483 | if (!desc.hasSetter()) desc.setSet(void 0); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 484 | } |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 485 | if (!desc.hasEnumerable()) desc.setEnumerable(false); |
| 486 | if (!desc.hasConfigurable()) desc.setConfigurable(false); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 487 | return desc; |
| 488 | } |
| 489 | |
| 490 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 491 | function PropertyDescriptor() { |
| 492 | // Initialize here so they are all in-object and have the same map. |
| 493 | // Default values from ES5 8.6.1. |
| 494 | this.value_ = void 0; |
| 495 | this.hasValue_ = false; |
| 496 | this.writable_ = false; |
| 497 | this.hasWritable_ = false; |
| 498 | this.enumerable_ = false; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 499 | this.hasEnumerable_ = false; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 500 | this.configurable_ = false; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 501 | this.hasConfigurable_ = false; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 502 | this.get_ = void 0; |
| 503 | this.hasGetter_ = false; |
| 504 | this.set_ = void 0; |
| 505 | this.hasSetter_ = false; |
| 506 | } |
| 507 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 508 | SetUpLockedPrototype(PropertyDescriptor, $Array( |
| 509 | "value_", |
| 510 | "hasValue_", |
| 511 | "writable_", |
| 512 | "hasWritable_", |
| 513 | "enumerable_", |
| 514 | "hasEnumerable_", |
| 515 | "configurable_", |
| 516 | "hasConfigurable_", |
| 517 | "get_", |
| 518 | "hasGetter_", |
| 519 | "set_", |
| 520 | "hasSetter_" |
| 521 | ), $Array( |
| 522 | "toString", function() { |
| 523 | return "[object PropertyDescriptor]"; |
| 524 | }, |
| 525 | "setValue", function(value) { |
| 526 | this.value_ = value; |
| 527 | this.hasValue_ = true; |
| 528 | }, |
| 529 | "getValue", function() { |
| 530 | return this.value_; |
| 531 | }, |
| 532 | "hasValue", function() { |
| 533 | return this.hasValue_; |
| 534 | }, |
| 535 | "setEnumerable", function(enumerable) { |
| 536 | this.enumerable_ = enumerable; |
| 537 | this.hasEnumerable_ = true; |
| 538 | }, |
| 539 | "isEnumerable", function () { |
| 540 | return this.enumerable_; |
| 541 | }, |
| 542 | "hasEnumerable", function() { |
| 543 | return this.hasEnumerable_; |
| 544 | }, |
| 545 | "setWritable", function(writable) { |
| 546 | this.writable_ = writable; |
| 547 | this.hasWritable_ = true; |
| 548 | }, |
| 549 | "isWritable", function() { |
| 550 | return this.writable_; |
| 551 | }, |
| 552 | "hasWritable", function() { |
| 553 | return this.hasWritable_; |
| 554 | }, |
| 555 | "setConfigurable", function(configurable) { |
| 556 | this.configurable_ = configurable; |
| 557 | this.hasConfigurable_ = true; |
| 558 | }, |
| 559 | "hasConfigurable", function() { |
| 560 | return this.hasConfigurable_; |
| 561 | }, |
| 562 | "isConfigurable", function() { |
| 563 | return this.configurable_; |
| 564 | }, |
| 565 | "setGet", function(get) { |
| 566 | this.get_ = get; |
| 567 | this.hasGetter_ = true; |
| 568 | }, |
| 569 | "getGet", function() { |
| 570 | return this.get_; |
| 571 | }, |
| 572 | "hasGetter", function() { |
| 573 | return this.hasGetter_; |
| 574 | }, |
| 575 | "setSet", function(set) { |
| 576 | this.set_ = set; |
| 577 | this.hasSetter_ = true; |
| 578 | }, |
| 579 | "getSet", function() { |
| 580 | return this.set_; |
| 581 | }, |
| 582 | "hasSetter", function() { |
| 583 | return this.hasSetter_; |
| 584 | })); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 585 | |
| 586 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 587 | // Converts an array returned from Runtime_GetOwnProperty to an actual |
| 588 | // property descriptor. For a description of the array layout please |
| 589 | // see the runtime.cc file. |
| 590 | function ConvertDescriptorArrayToDescriptor(desc_array) { |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 591 | if (desc_array === false) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 592 | throw 'Internal error: invalid desc_array'; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 593 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 594 | |
| 595 | if (IS_UNDEFINED(desc_array)) { |
| 596 | return void 0; |
| 597 | } |
| 598 | |
| 599 | var desc = new PropertyDescriptor(); |
| 600 | // This is an accessor. |
| 601 | if (desc_array[IS_ACCESSOR_INDEX]) { |
| 602 | desc.setGet(desc_array[GETTER_INDEX]); |
| 603 | desc.setSet(desc_array[SETTER_INDEX]); |
| 604 | } else { |
| 605 | desc.setValue(desc_array[VALUE_INDEX]); |
| 606 | desc.setWritable(desc_array[WRITABLE_INDEX]); |
| 607 | } |
| 608 | desc.setEnumerable(desc_array[ENUMERABLE_INDEX]); |
| 609 | desc.setConfigurable(desc_array[CONFIGURABLE_INDEX]); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 610 | |
| 611 | return desc; |
| 612 | } |
| 613 | |
| 614 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 615 | // For Harmony proxies. |
| 616 | function GetTrap(handler, name, defaultTrap) { |
| 617 | var trap = handler[name]; |
| 618 | if (IS_UNDEFINED(trap)) { |
| 619 | if (IS_UNDEFINED(defaultTrap)) { |
| 620 | throw MakeTypeError("handler_trap_missing", [handler, name]); |
| 621 | } |
| 622 | trap = defaultTrap; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 623 | } else if (!IS_SPEC_FUNCTION(trap)) { |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 624 | throw MakeTypeError("handler_trap_must_be_callable", [handler, name]); |
| 625 | } |
| 626 | return trap; |
| 627 | } |
| 628 | |
| 629 | |
| 630 | function CallTrap0(handler, name, defaultTrap) { |
| 631 | return %_CallFunction(handler, GetTrap(handler, name, defaultTrap)); |
| 632 | } |
| 633 | |
| 634 | |
| 635 | function CallTrap1(handler, name, defaultTrap, x) { |
| 636 | return %_CallFunction(handler, x, GetTrap(handler, name, defaultTrap)); |
| 637 | } |
| 638 | |
| 639 | |
| 640 | function CallTrap2(handler, name, defaultTrap, x, y) { |
| 641 | return %_CallFunction(handler, x, y, GetTrap(handler, name, defaultTrap)); |
| 642 | } |
| 643 | |
| 644 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 645 | // ES5 section 8.12.1. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 646 | function GetOwnProperty(obj, v) { |
| 647 | var p = ToString(v); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 648 | if (%IsJSProxy(obj)) { |
| 649 | var handler = %GetHandler(obj); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 650 | var descriptor = CallTrap1(handler, "getOwnPropertyDescriptor", void 0, p); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 651 | if (IS_UNDEFINED(descriptor)) return descriptor; |
| 652 | var desc = ToCompletePropertyDescriptor(descriptor); |
| 653 | if (!desc.isConfigurable()) { |
| 654 | throw MakeTypeError("proxy_prop_not_configurable", |
| 655 | [handler, "getOwnPropertyDescriptor", p, descriptor]); |
| 656 | } |
| 657 | return desc; |
| 658 | } |
| 659 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 660 | // GetOwnProperty returns an array indexed by the constants |
| 661 | // defined in macros.py. |
| 662 | // If p is not a property on obj undefined is returned. |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 663 | var props = %GetOwnProperty(ToObject(obj), ToString(v)); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 664 | |
| 665 | // A false value here means that access checks failed. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 666 | if (props === false) return void 0; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 667 | |
| 668 | return ConvertDescriptorArrayToDescriptor(props); |
| 669 | } |
| 670 | |
| 671 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 672 | // ES5 section 8.12.7. |
| 673 | function Delete(obj, p, should_throw) { |
| 674 | var desc = GetOwnProperty(obj, p); |
| 675 | if (IS_UNDEFINED(desc)) return true; |
| 676 | if (desc.isConfigurable()) { |
| 677 | %DeleteProperty(obj, p, 0); |
| 678 | return true; |
| 679 | } else if (should_throw) { |
| 680 | throw MakeTypeError("define_disallowed", [p]); |
| 681 | } else { |
| 682 | return; |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 687 | // Harmony proxies. |
| 688 | function DefineProxyProperty(obj, p, attributes, should_throw) { |
| 689 | var handler = %GetHandler(obj); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 690 | var result = CallTrap2(handler, "defineProperty", void 0, p, attributes); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 691 | if (!ToBoolean(result)) { |
| 692 | if (should_throw) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 693 | throw MakeTypeError("handler_returned_false", |
| 694 | [handler, "defineProperty"]); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 695 | } else { |
| 696 | return false; |
| 697 | } |
| 698 | } |
| 699 | return true; |
| 700 | } |
| 701 | |
| 702 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 703 | // ES5 8.12.9. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 704 | function DefineObjectProperty(obj, p, desc, should_throw) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 705 | var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); |
| 706 | // A false value here means that access checks failed. |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 707 | if (current_or_access === false) return void 0; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 708 | |
| 709 | var current = ConvertDescriptorArrayToDescriptor(current_or_access); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 710 | var extensible = %IsExtensible(ToObject(obj)); |
| 711 | |
| 712 | // Error handling according to spec. |
| 713 | // Step 3 |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 714 | if (IS_UNDEFINED(current) && !extensible) { |
| 715 | if (should_throw) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 716 | throw MakeTypeError("define_disallowed", [p]); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 717 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 718 | return false; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 719 | } |
| 720 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 721 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 722 | if (!IS_UNDEFINED(current)) { |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 723 | // Step 5 and 6 |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 724 | if ((IsGenericDescriptor(desc) || |
| 725 | IsDataDescriptor(desc) == IsDataDescriptor(current)) && |
| 726 | (!desc.hasEnumerable() || |
| 727 | SameValue(desc.isEnumerable(), current.isEnumerable())) && |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 728 | (!desc.hasConfigurable() || |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 729 | SameValue(desc.isConfigurable(), current.isConfigurable())) && |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 730 | (!desc.hasWritable() || |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 731 | SameValue(desc.isWritable(), current.isWritable())) && |
| 732 | (!desc.hasValue() || |
| 733 | SameValue(desc.getValue(), current.getValue())) && |
| 734 | (!desc.hasGetter() || |
| 735 | SameValue(desc.getGet(), current.getGet())) && |
| 736 | (!desc.hasSetter() || |
| 737 | SameValue(desc.getSet(), current.getSet()))) { |
| 738 | return true; |
| 739 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 740 | if (!current.isConfigurable()) { |
| 741 | // Step 7 |
| 742 | if (desc.isConfigurable() || |
| 743 | (desc.hasEnumerable() && |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 744 | desc.isEnumerable() != current.isEnumerable())) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 745 | if (should_throw) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 746 | throw MakeTypeError("redefine_disallowed", [p]); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 747 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 748 | return false; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 749 | } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 750 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 751 | // Step 8 |
| 752 | if (!IsGenericDescriptor(desc)) { |
| 753 | // Step 9a |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 754 | if (IsDataDescriptor(current) != IsDataDescriptor(desc)) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 755 | if (should_throw) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 756 | throw MakeTypeError("redefine_disallowed", [p]); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 757 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 758 | return false; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 759 | } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 760 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 761 | // Step 10a |
| 762 | if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 763 | if (!current.isWritable() && desc.isWritable()) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 764 | if (should_throw) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 765 | throw MakeTypeError("redefine_disallowed", [p]); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 766 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 767 | return false; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 768 | } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 769 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 770 | if (!current.isWritable() && desc.hasValue() && |
| 771 | !SameValue(desc.getValue(), current.getValue())) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 772 | if (should_throw) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 773 | throw MakeTypeError("redefine_disallowed", [p]); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 774 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 775 | return false; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 776 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | // Step 11 |
| 780 | if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 781 | if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 782 | if (should_throw) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 783 | throw MakeTypeError("redefine_disallowed", [p]); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 784 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 785 | return false; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 786 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 787 | } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 788 | if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) { |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 789 | if (should_throw) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 790 | throw MakeTypeError("redefine_disallowed", [p]); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 791 | } else { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 792 | return false; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 793 | } |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 794 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 795 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 796 | } |
| 797 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 798 | } |
| 799 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 800 | // Send flags - enumerable and configurable are common - writable is |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 801 | // only send to the data descriptor. |
| 802 | // Take special care if enumerable and configurable is not defined on |
| 803 | // desc (we need to preserve the existing values from current). |
| 804 | var flag = NONE; |
| 805 | if (desc.hasEnumerable()) { |
| 806 | flag |= desc.isEnumerable() ? 0 : DONT_ENUM; |
| 807 | } else if (!IS_UNDEFINED(current)) { |
| 808 | flag |= current.isEnumerable() ? 0 : DONT_ENUM; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 809 | } else { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 810 | flag |= DONT_ENUM; |
| 811 | } |
| 812 | |
| 813 | if (desc.hasConfigurable()) { |
| 814 | flag |= desc.isConfigurable() ? 0 : DONT_DELETE; |
| 815 | } else if (!IS_UNDEFINED(current)) { |
| 816 | flag |= current.isConfigurable() ? 0 : DONT_DELETE; |
| 817 | } else |
| 818 | flag |= DONT_DELETE; |
| 819 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 820 | if (IsDataDescriptor(desc) || |
| 821 | (IsGenericDescriptor(desc) && |
| 822 | (IS_UNDEFINED(current) || IsDataDescriptor(current)))) { |
| 823 | // There are 3 cases that lead here: |
| 824 | // Step 4a - defining a new data property. |
| 825 | // Steps 9b & 12 - replacing an existing accessor property with a data |
| 826 | // property. |
| 827 | // Step 12 - updating an existing data property with a data or generic |
| 828 | // descriptor. |
| 829 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 830 | if (desc.hasWritable()) { |
| 831 | flag |= desc.isWritable() ? 0 : READ_ONLY; |
| 832 | } else if (!IS_UNDEFINED(current)) { |
| 833 | flag |= current.isWritable() ? 0 : READ_ONLY; |
| 834 | } else { |
| 835 | flag |= READ_ONLY; |
| 836 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 837 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 838 | var value = void 0; // Default value is undefined. |
| 839 | if (desc.hasValue()) { |
| 840 | value = desc.getValue(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 841 | } else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 842 | value = current.getValue(); |
| 843 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 844 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 845 | %DefineOrRedefineDataProperty(obj, p, value, flag); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 846 | } else { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 847 | // There are 3 cases that lead here: |
| 848 | // Step 4b - defining a new accessor property. |
| 849 | // Steps 9c & 12 - replacing an existing data property with an accessor |
| 850 | // property. |
| 851 | // Step 12 - updating an existing accessor property with an accessor |
| 852 | // descriptor. |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 853 | var getter = desc.hasGetter() ? desc.getGet() : null; |
| 854 | var setter = desc.hasSetter() ? desc.getSet() : null; |
| 855 | %DefineOrRedefineAccessorProperty(obj, p, getter, setter, flag); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 856 | } |
| 857 | return true; |
| 858 | } |
| 859 | |
| 860 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 861 | // ES5 section 15.4.5.1. |
| 862 | function DefineArrayProperty(obj, p, desc, should_throw) { |
| 863 | // Note that the length of an array is not actually stored as part of the |
| 864 | // property, hence we use generated code throughout this function instead of |
| 865 | // DefineObjectProperty() to modify its value. |
| 866 | |
| 867 | // Step 3 - Special handling for length property. |
| 868 | if (p == "length") { |
| 869 | var length = obj.length; |
| 870 | if (!desc.hasValue()) { |
| 871 | return DefineObjectProperty(obj, "length", desc, should_throw); |
| 872 | } |
| 873 | var new_length = ToUint32(desc.getValue()); |
| 874 | if (new_length != ToNumber(desc.getValue())) { |
| 875 | throw new $RangeError('defineProperty() array length out of range'); |
| 876 | } |
| 877 | var length_desc = GetOwnProperty(obj, "length"); |
| 878 | if (new_length != length && !length_desc.isWritable()) { |
| 879 | if (should_throw) { |
| 880 | throw MakeTypeError("redefine_disallowed", [p]); |
| 881 | } else { |
| 882 | return false; |
| 883 | } |
| 884 | } |
| 885 | var threw = false; |
| 886 | while (new_length < length--) { |
| 887 | if (!Delete(obj, ToString(length), false)) { |
| 888 | new_length = length + 1; |
| 889 | threw = true; |
| 890 | break; |
| 891 | } |
| 892 | } |
| 893 | // Make sure the below call to DefineObjectProperty() doesn't overwrite |
| 894 | // any magic "length" property by removing the value. |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 895 | // TODO(mstarzinger): This hack should be removed once we have addressed the |
| 896 | // respective TODO in Runtime_DefineOrRedefineDataProperty. |
| 897 | // For the time being, we need a hack to prevent Object.observe from |
| 898 | // generating two change records. |
| 899 | var isObserved = %IsObserved(obj); |
| 900 | if (isObserved) %SetIsObserved(obj, false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 901 | obj.length = new_length; |
| 902 | desc.value_ = void 0; |
| 903 | desc.hasValue_ = false; |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 904 | threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw; |
| 905 | if (isObserved) %SetIsObserved(obj, true); |
| 906 | if (threw) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 907 | if (should_throw) { |
| 908 | throw MakeTypeError("redefine_disallowed", [p]); |
| 909 | } else { |
| 910 | return false; |
| 911 | } |
| 912 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 913 | if (isObserved) { |
| 914 | var new_desc = GetOwnProperty(obj, "length"); |
| 915 | var updated = length_desc.value_ !== new_desc.value_; |
| 916 | var reconfigured = length_desc.writable_ !== new_desc.writable_ || |
| 917 | length_desc.configurable_ !== new_desc.configurable_ || |
| 918 | length_desc.enumerable_ !== new_desc.configurable_; |
| 919 | if (updated || reconfigured) { |
| 920 | NotifyChange(reconfigured ? "reconfigured" : "updated", |
| 921 | obj, "length", length_desc.value_); |
| 922 | } |
| 923 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 924 | return true; |
| 925 | } |
| 926 | |
| 927 | // Step 4 - Special handling for array index. |
| 928 | var index = ToUint32(p); |
| 929 | if (index == ToNumber(p) && index != 4294967295) { |
| 930 | var length = obj.length; |
| 931 | var length_desc = GetOwnProperty(obj, "length"); |
| 932 | if ((index >= length && !length_desc.isWritable()) || |
| 933 | !DefineObjectProperty(obj, p, desc, true)) { |
| 934 | if (should_throw) { |
| 935 | throw MakeTypeError("define_disallowed", [p]); |
| 936 | } else { |
| 937 | return false; |
| 938 | } |
| 939 | } |
| 940 | if (index >= length) { |
| 941 | obj.length = index + 1; |
| 942 | } |
| 943 | return true; |
| 944 | } |
| 945 | |
| 946 | // Step 5 - Fallback to default implementation. |
| 947 | return DefineObjectProperty(obj, p, desc, should_throw); |
| 948 | } |
| 949 | |
| 950 | |
| 951 | // ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies. |
| 952 | function DefineOwnProperty(obj, p, desc, should_throw) { |
| 953 | if (%IsJSProxy(obj)) { |
| 954 | var attributes = FromGenericPropertyDescriptor(desc); |
| 955 | return DefineProxyProperty(obj, p, attributes, should_throw); |
| 956 | } else if (IS_ARRAY(obj)) { |
| 957 | return DefineArrayProperty(obj, p, desc, should_throw); |
| 958 | } else { |
| 959 | return DefineObjectProperty(obj, p, desc, should_throw); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 964 | // ES5 section 15.2.3.2. |
| 965 | function ObjectGetPrototypeOf(obj) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 966 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 967 | throw MakeTypeError("called_on_non_object", ["Object.getPrototypeOf"]); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 968 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 969 | return %GetPrototype(obj); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 973 | // ES5 section 15.2.3.3 |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 974 | function ObjectGetOwnPropertyDescriptor(obj, p) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 975 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 976 | throw MakeTypeError("called_on_non_object", |
| 977 | ["Object.getOwnPropertyDescriptor"]); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 978 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 979 | var desc = GetOwnProperty(obj, p); |
| 980 | return FromPropertyDescriptor(desc); |
| 981 | } |
| 982 | |
| 983 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 984 | // For Harmony proxies |
| 985 | function ToStringArray(obj, trap) { |
| 986 | if (!IS_SPEC_OBJECT(obj)) { |
| 987 | throw MakeTypeError("proxy_non_object_prop_names", [obj, trap]); |
| 988 | } |
| 989 | var n = ToUint32(obj.length); |
| 990 | var array = new $Array(n); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 991 | var names = { __proto__: null }; // TODO(rossberg): use sets once ready. |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 992 | for (var index = 0; index < n; index++) { |
| 993 | var s = ToString(obj[index]); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 994 | if (%HasLocalProperty(names, s)) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 995 | throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 996 | } |
| 997 | array[index] = s; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 998 | names[s] = 0; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 999 | } |
| 1000 | return array; |
| 1001 | } |
| 1002 | |
| 1003 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1004 | // ES5 section 15.2.3.4. |
| 1005 | function ObjectGetOwnPropertyNames(obj) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1006 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1007 | throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1008 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1009 | // Special handling for proxies. |
| 1010 | if (%IsJSProxy(obj)) { |
| 1011 | var handler = %GetHandler(obj); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1012 | var names = CallTrap0(handler, "getOwnPropertyNames", void 0); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1013 | return ToStringArray(names, "getOwnPropertyNames"); |
| 1014 | } |
| 1015 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1016 | // Find all the indexed properties. |
| 1017 | |
| 1018 | // Get the local element names. |
| 1019 | var propertyNames = %GetLocalElementNames(obj); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1020 | for (var i = 0; i < propertyNames.length; ++i) { |
| 1021 | propertyNames[i] = %_NumberToString(propertyNames[i]); |
| 1022 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1023 | |
| 1024 | // Get names for indexed interceptor properties. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1025 | var interceptorInfo = %GetInterceptorInfo(obj); |
| 1026 | if ((interceptorInfo & 1) != 0) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1027 | var indexedInterceptorNames = |
| 1028 | %GetIndexedInterceptorElementNames(obj); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1029 | if (indexedInterceptorNames) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1030 | propertyNames = propertyNames.concat(indexedInterceptorNames); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1031 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | // Find all the named properties. |
| 1035 | |
| 1036 | // Get the local property names. |
| 1037 | propertyNames = propertyNames.concat(%GetLocalPropertyNames(obj)); |
| 1038 | |
| 1039 | // Get names for named interceptor properties if any. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1040 | if ((interceptorInfo & 2) != 0) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1041 | var namedInterceptorNames = |
| 1042 | %GetNamedInterceptorPropertyNames(obj); |
| 1043 | if (namedInterceptorNames) { |
| 1044 | propertyNames = propertyNames.concat(namedInterceptorNames); |
| 1045 | } |
| 1046 | } |
| 1047 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1048 | // Property names are expected to be unique strings, |
| 1049 | // but interceptors can interfere with that assumption. |
| 1050 | if (interceptorInfo != 0) { |
| 1051 | var propertySet = { __proto__: null }; |
| 1052 | var j = 0; |
| 1053 | for (var i = 0; i < propertyNames.length; ++i) { |
| 1054 | var name = ToString(propertyNames[i]); |
| 1055 | // We need to check for the exact property value since for intrinsic |
| 1056 | // properties like toString if(propertySet["toString"]) will always |
| 1057 | // succeed. |
| 1058 | if (propertySet[name] === true) { |
| 1059 | continue; |
| 1060 | } |
| 1061 | propertySet[name] = true; |
| 1062 | propertyNames[j++] = name; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1063 | } |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1064 | propertyNames.length = j; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1065 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1066 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1067 | return propertyNames; |
| 1068 | } |
| 1069 | |
| 1070 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1071 | // ES5 section 15.2.3.5. |
| 1072 | function ObjectCreate(proto, properties) { |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1073 | if (!IS_SPEC_OBJECT(proto) && proto !== null) { |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1074 | throw MakeTypeError("proto_object_or_null", [proto]); |
| 1075 | } |
| 1076 | var obj = new $Object(); |
| 1077 | obj.__proto__ = proto; |
| 1078 | if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
| 1079 | return obj; |
| 1080 | } |
| 1081 | |
| 1082 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1083 | // ES5 section 15.2.3.6. |
| 1084 | function ObjectDefineProperty(obj, p, attributes) { |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1085 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1086 | throw MakeTypeError("called_on_non_object", ["Object.defineProperty"]); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1087 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1088 | var name = ToString(p); |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1089 | if (%IsJSProxy(obj)) { |
| 1090 | // Clone the attributes object for protection. |
| 1091 | // TODO(rossberg): not spec'ed yet, so not sure if this should involve |
| 1092 | // non-own properties as it does (or non-enumerable ones, as it doesn't?). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1093 | var attributesClone = { __proto__: null }; |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 1094 | for (var a in attributes) { |
| 1095 | attributesClone[a] = attributes[a]; |
| 1096 | } |
| 1097 | DefineProxyProperty(obj, name, attributesClone, true); |
| 1098 | // The following would implement the spec as in the current proposal, |
| 1099 | // but after recent comments on es-discuss, is most likely obsolete. |
| 1100 | /* |
| 1101 | var defineObj = FromGenericPropertyDescriptor(desc); |
| 1102 | var names = ObjectGetOwnPropertyNames(attributes); |
| 1103 | var standardNames = |
| 1104 | {value: 0, writable: 0, get: 0, set: 0, enumerable: 0, configurable: 0}; |
| 1105 | for (var i = 0; i < names.length; i++) { |
| 1106 | var N = names[i]; |
| 1107 | if (!(%HasLocalProperty(standardNames, N))) { |
| 1108 | var attr = GetOwnProperty(attributes, N); |
| 1109 | DefineOwnProperty(descObj, N, attr, true); |
| 1110 | } |
| 1111 | } |
| 1112 | // This is really confusing the types, but it is what the proxies spec |
| 1113 | // currently requires: |
| 1114 | desc = descObj; |
| 1115 | */ |
| 1116 | } else { |
| 1117 | var desc = ToPropertyDescriptor(attributes); |
| 1118 | DefineOwnProperty(obj, name, desc, true); |
| 1119 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1120 | return obj; |
| 1121 | } |
| 1122 | |
| 1123 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1124 | function GetOwnEnumerablePropertyNames(properties) { |
| 1125 | var names = new InternalArray(); |
| 1126 | for (var key in properties) { |
| 1127 | if (%HasLocalProperty(properties, key)) { |
| 1128 | names.push(key); |
| 1129 | } |
| 1130 | } |
| 1131 | return names; |
| 1132 | } |
| 1133 | |
| 1134 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1135 | // ES5 section 15.2.3.7. |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1136 | function ObjectDefineProperties(obj, properties) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1137 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1138 | throw MakeTypeError("called_on_non_object", ["Object.defineProperties"]); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1139 | } |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1140 | var props = ToObject(properties); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1141 | var names = GetOwnEnumerablePropertyNames(props); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1142 | var descriptors = new InternalArray(); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1143 | for (var i = 0; i < names.length; i++) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1144 | descriptors.push(ToPropertyDescriptor(props[names[i]])); |
| 1145 | } |
| 1146 | for (var i = 0; i < names.length; i++) { |
| 1147 | DefineOwnProperty(obj, names[i], descriptors[i], true); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1148 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1149 | return obj; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1153 | // Harmony proxies. |
| 1154 | function ProxyFix(obj) { |
| 1155 | var handler = %GetHandler(obj); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 1156 | var props = CallTrap0(handler, "fix", void 0); |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1157 | if (IS_UNDEFINED(props)) { |
| 1158 | throw MakeTypeError("handler_returned_undefined", [handler, "fix"]); |
| 1159 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1160 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1161 | if (%IsJSFunctionProxy(obj)) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1162 | var callTrap = %GetCallTrap(obj); |
| 1163 | var constructTrap = %GetConstructTrap(obj); |
| 1164 | var code = DelegateCallAndConstruct(callTrap, constructTrap); |
| 1165 | %Fix(obj); // becomes a regular function |
| 1166 | %SetCode(obj, code); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1167 | // TODO(rossberg): What about length and other properties? Not specified. |
| 1168 | // We just put in some half-reasonable defaults for now. |
| 1169 | var prototype = new $Object(); |
| 1170 | $Object.defineProperty(prototype, "constructor", |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 1171 | {value: obj, writable: true, enumerable: false, configurable: true}); |
| 1172 | // TODO(v8:1530): defineProperty does not handle prototype and length. |
| 1173 | %FunctionSetPrototype(obj, prototype); |
| 1174 | obj.length = 0; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1175 | } else { |
| 1176 | %Fix(obj); |
| 1177 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1178 | ObjectDefineProperties(obj, props); |
| 1179 | } |
| 1180 | |
| 1181 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1182 | // ES5 section 15.2.3.8. |
| 1183 | function ObjectSeal(obj) { |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1184 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1185 | throw MakeTypeError("called_on_non_object", ["Object.seal"]); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1186 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1187 | if (%IsJSProxy(obj)) { |
| 1188 | ProxyFix(obj); |
| 1189 | } |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1190 | var names = ObjectGetOwnPropertyNames(obj); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1191 | for (var i = 0; i < names.length; i++) { |
| 1192 | var name = names[i]; |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1193 | var desc = GetOwnProperty(obj, name); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1194 | if (desc.isConfigurable()) { |
| 1195 | desc.setConfigurable(false); |
| 1196 | DefineOwnProperty(obj, name, desc, true); |
| 1197 | } |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 1198 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1199 | %PreventExtensions(obj); |
| 1200 | return obj; |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1204 | // ES5 section 15.2.3.9. |
| 1205 | function ObjectFreeze(obj) { |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1206 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1207 | throw MakeTypeError("called_on_non_object", ["Object.freeze"]); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1208 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1209 | if (%IsJSProxy(obj)) { |
| 1210 | ProxyFix(obj); |
| 1211 | } |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1212 | var names = ObjectGetOwnPropertyNames(obj); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1213 | for (var i = 0; i < names.length; i++) { |
| 1214 | var name = names[i]; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1215 | var desc = GetOwnProperty(obj, name); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1216 | if (desc.isWritable() || desc.isConfigurable()) { |
| 1217 | if (IsDataDescriptor(desc)) desc.setWritable(false); |
| 1218 | desc.setConfigurable(false); |
| 1219 | DefineOwnProperty(obj, name, desc, true); |
| 1220 | } |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 1221 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1222 | %PreventExtensions(obj); |
| 1223 | return obj; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1227 | // ES5 section 15.2.3.10 |
| 1228 | function ObjectPreventExtension(obj) { |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1229 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1230 | throw MakeTypeError("called_on_non_object", ["Object.preventExtension"]); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1231 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1232 | if (%IsJSProxy(obj)) { |
| 1233 | ProxyFix(obj); |
| 1234 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1235 | %PreventExtensions(obj); |
| 1236 | return obj; |
| 1237 | } |
| 1238 | |
| 1239 | |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1240 | // ES5 section 15.2.3.11 |
| 1241 | function ObjectIsSealed(obj) { |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1242 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1243 | throw MakeTypeError("called_on_non_object", ["Object.isSealed"]); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1244 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1245 | if (%IsJSProxy(obj)) { |
| 1246 | return false; |
| 1247 | } |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1248 | if (%IsExtensible(obj)) { |
| 1249 | return false; |
| 1250 | } |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1251 | var names = ObjectGetOwnPropertyNames(obj); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1252 | for (var i = 0; i < names.length; i++) { |
| 1253 | var name = names[i]; |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1254 | var desc = GetOwnProperty(obj, name); |
| 1255 | if (desc.isConfigurable()) return false; |
| 1256 | } |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1257 | return true; |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1261 | // ES5 section 15.2.3.12 |
| 1262 | function ObjectIsFrozen(obj) { |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1263 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1264 | throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1265 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1266 | if (%IsJSProxy(obj)) { |
| 1267 | return false; |
| 1268 | } |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1269 | if (%IsExtensible(obj)) { |
| 1270 | return false; |
| 1271 | } |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1272 | var names = ObjectGetOwnPropertyNames(obj); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1273 | for (var i = 0; i < names.length; i++) { |
| 1274 | var name = names[i]; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1275 | var desc = GetOwnProperty(obj, name); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1276 | if (IsDataDescriptor(desc) && desc.isWritable()) return false; |
| 1277 | if (desc.isConfigurable()) return false; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1278 | } |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1279 | return true; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1283 | // ES5 section 15.2.3.13 |
| 1284 | function ObjectIsExtensible(obj) { |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1285 | if (!IS_SPEC_OBJECT(obj)) { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1286 | throw MakeTypeError("called_on_non_object", ["Object.isExtensible"]); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1287 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1288 | if (%IsJSProxy(obj)) { |
| 1289 | return true; |
| 1290 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1291 | return %IsExtensible(obj); |
| 1292 | } |
| 1293 | |
| 1294 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 1295 | // Harmony egal. |
| 1296 | function ObjectIs(obj1, obj2) { |
| 1297 | if (obj1 === obj2) { |
| 1298 | return (obj1 !== 0) || (1 / obj1 === 1 / obj2); |
| 1299 | } else { |
| 1300 | return (obj1 !== obj1) && (obj2 !== obj2); |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1305 | %SetCode($Object, function(x) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1306 | if (%_IsConstructCall()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1307 | if (x == null) return this; |
| 1308 | return ToObject(x); |
| 1309 | } else { |
| 1310 | if (x == null) return { }; |
| 1311 | return ToObject(x); |
| 1312 | } |
| 1313 | }); |
| 1314 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1315 | %SetExpectedNumberOfProperties($Object, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1316 | |
| 1317 | // ---------------------------------------------------------------------------- |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1318 | // Object |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1319 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1320 | function SetUpObject() { |
| 1321 | %CheckIsBootstrapping(); |
| 1322 | // Set Up non-enumerable functions on the Object.prototype object. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1323 | InstallFunctions($Object.prototype, DONT_ENUM, $Array( |
| 1324 | "toString", ObjectToString, |
| 1325 | "toLocaleString", ObjectToLocaleString, |
| 1326 | "valueOf", ObjectValueOf, |
| 1327 | "hasOwnProperty", ObjectHasOwnProperty, |
| 1328 | "isPrototypeOf", ObjectIsPrototypeOf, |
| 1329 | "propertyIsEnumerable", ObjectPropertyIsEnumerable, |
| 1330 | "__defineGetter__", ObjectDefineGetter, |
| 1331 | "__lookupGetter__", ObjectLookupGetter, |
| 1332 | "__defineSetter__", ObjectDefineSetter, |
| 1333 | "__lookupSetter__", ObjectLookupSetter |
| 1334 | )); |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1335 | InstallFunctions($Object, DONT_ENUM, $Array( |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 1336 | "keys", ObjectKeys, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1337 | "create", ObjectCreate, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1338 | "defineProperty", ObjectDefineProperty, |
| 1339 | "defineProperties", ObjectDefineProperties, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1340 | "freeze", ObjectFreeze, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1341 | "getPrototypeOf", ObjectGetPrototypeOf, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1342 | "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1343 | "getOwnPropertyNames", ObjectGetOwnPropertyNames, |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 1344 | "is", ObjectIs, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1345 | "isExtensible", ObjectIsExtensible, |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 1346 | "isFrozen", ObjectIsFrozen, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1347 | "isSealed", ObjectIsSealed, |
| 1348 | "preventExtensions", ObjectPreventExtension, |
| 1349 | "seal", ObjectSeal |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1350 | )); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1351 | } |
| 1352 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1353 | SetUpObject(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1354 | |
| 1355 | // ---------------------------------------------------------------------------- |
| 1356 | // Boolean |
| 1357 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1358 | function BooleanToString() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1359 | // NOTE: Both Boolean objects and values can enter here as |
| 1360 | // 'this'. This is not as dictated by ECMA-262. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1361 | var b = this; |
| 1362 | if (!IS_BOOLEAN(b)) { |
| 1363 | if (!IS_BOOLEAN_WRAPPER(b)) { |
| 1364 | throw new $TypeError('Boolean.prototype.toString is not generic'); |
| 1365 | } |
| 1366 | b = %_ValueOf(b); |
| 1367 | } |
| 1368 | return b ? 'true' : 'false'; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1369 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1370 | |
| 1371 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1372 | function BooleanValueOf() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1373 | // NOTE: Both Boolean objects and values can enter here as |
| 1374 | // 'this'. This is not as dictated by ECMA-262. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1375 | if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1376 | throw new $TypeError('Boolean.prototype.valueOf is not generic'); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1377 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1378 | return %_ValueOf(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1379 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1380 | |
| 1381 | |
| 1382 | // ---------------------------------------------------------------------------- |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1383 | |
| 1384 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1385 | function SetUpBoolean () { |
| 1386 | %CheckIsBootstrapping(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1387 | InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( |
| 1388 | "toString", BooleanToString, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1389 | "valueOf", BooleanValueOf |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1390 | )); |
| 1391 | } |
| 1392 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1393 | SetUpBoolean(); |
| 1394 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1395 | |
| 1396 | // ---------------------------------------------------------------------------- |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1397 | // Number |
| 1398 | |
| 1399 | // Set the Number function and constructor. |
| 1400 | %SetCode($Number, function(x) { |
| 1401 | var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1402 | if (%_IsConstructCall()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1403 | %_SetValueOf(this, value); |
| 1404 | } else { |
| 1405 | return value; |
| 1406 | } |
| 1407 | }); |
| 1408 | |
| 1409 | %FunctionSetPrototype($Number, new $Number(0)); |
| 1410 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1411 | // ECMA-262 section 15.7.4.2. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1412 | function NumberToString(radix) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1413 | // NOTE: Both Number objects and values can enter here as |
| 1414 | // 'this'. This is not as dictated by ECMA-262. |
| 1415 | var number = this; |
| 1416 | if (!IS_NUMBER(this)) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1417 | if (!IS_NUMBER_WRAPPER(this)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1418 | throw new $TypeError('Number.prototype.toString is not generic'); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1419 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1420 | // Get the value of this number in case it's an object. |
| 1421 | number = %_ValueOf(this); |
| 1422 | } |
| 1423 | // Fast case: Convert number in radix 10. |
| 1424 | if (IS_UNDEFINED(radix) || radix === 10) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1425 | return %_NumberToString(number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | // Convert the radix to an integer and check the range. |
| 1429 | radix = TO_INTEGER(radix); |
| 1430 | if (radix < 2 || radix > 36) { |
| 1431 | throw new $RangeError('toString() radix argument must be between 2 and 36'); |
| 1432 | } |
| 1433 | // Convert the number to a string in the given radix. |
| 1434 | return %NumberToRadixString(number, radix); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1435 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1436 | |
| 1437 | |
| 1438 | // ECMA-262 section 15.7.4.3 |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1439 | function NumberToLocaleString() { |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1440 | return %_CallFunction(this, NumberToString); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1441 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1442 | |
| 1443 | |
| 1444 | // ECMA-262 section 15.7.4.4 |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1445 | function NumberValueOf() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1446 | // NOTE: Both Number objects and values can enter here as |
| 1447 | // 'this'. This is not as dictated by ECMA-262. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1448 | if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1449 | throw new $TypeError('Number.prototype.valueOf is not generic'); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1450 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1451 | return %_ValueOf(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1452 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1453 | |
| 1454 | |
| 1455 | // ECMA-262 section 15.7.4.5 |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1456 | function NumberToFixed(fractionDigits) { |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1457 | var x = this; |
| 1458 | if (!IS_NUMBER(this)) { |
| 1459 | if (!IS_NUMBER_WRAPPER(this)) { |
| 1460 | throw MakeTypeError("incompatible_method_receiver", |
| 1461 | ["Number.prototype.toFixed", this]); |
| 1462 | } |
| 1463 | // Get the value of this number in case it's an object. |
| 1464 | x = %_ValueOf(this); |
| 1465 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1466 | var f = TO_INTEGER(fractionDigits); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1467 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1468 | if (f < 0 || f > 20) { |
| 1469 | throw new $RangeError("toFixed() digits argument must be between 0 and 20"); |
| 1470 | } |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1471 | |
| 1472 | if (NUMBER_IS_NAN(x)) return "NaN"; |
| 1473 | if (x == 1/0) return "Infinity"; |
| 1474 | if (x == -1/0) return "-Infinity"; |
| 1475 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1476 | return %NumberToFixed(x, f); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1477 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1478 | |
| 1479 | |
| 1480 | // ECMA-262 section 15.7.4.6 |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1481 | function NumberToExponential(fractionDigits) { |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1482 | var x = this; |
| 1483 | if (!IS_NUMBER(this)) { |
| 1484 | if (!IS_NUMBER_WRAPPER(this)) { |
| 1485 | throw MakeTypeError("incompatible_method_receiver", |
| 1486 | ["Number.prototype.toExponential", this]); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1487 | } |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1488 | // Get the value of this number in case it's an object. |
| 1489 | x = %_ValueOf(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1490 | } |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1491 | var f = IS_UNDEFINED(fractionDigits) ? void 0 : TO_INTEGER(fractionDigits); |
| 1492 | |
| 1493 | if (NUMBER_IS_NAN(x)) return "NaN"; |
| 1494 | if (x == 1/0) return "Infinity"; |
| 1495 | if (x == -1/0) return "-Infinity"; |
| 1496 | |
| 1497 | if (IS_UNDEFINED(f)) { |
| 1498 | f = -1; // Signal for runtime function that f is not defined. |
| 1499 | } else if (f < 0 || f > 20) { |
| 1500 | throw new $RangeError("toExponential() argument must be between 0 and 20"); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1501 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1502 | return %NumberToExponential(x, f); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1503 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1504 | |
| 1505 | |
| 1506 | // ECMA-262 section 15.7.4.7 |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1507 | function NumberToPrecision(precision) { |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1508 | var x = this; |
| 1509 | if (!IS_NUMBER(this)) { |
| 1510 | if (!IS_NUMBER_WRAPPER(this)) { |
| 1511 | throw MakeTypeError("incompatible_method_receiver", |
| 1512 | ["Number.prototype.toPrecision", this]); |
| 1513 | } |
| 1514 | // Get the value of this number in case it's an object. |
| 1515 | x = %_ValueOf(this); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 1516 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1517 | if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); |
| 1518 | var p = TO_INTEGER(precision); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1519 | |
| 1520 | if (NUMBER_IS_NAN(x)) return "NaN"; |
| 1521 | if (x == 1/0) return "Infinity"; |
| 1522 | if (x == -1/0) return "-Infinity"; |
| 1523 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1524 | if (p < 1 || p > 21) { |
| 1525 | throw new $RangeError("toPrecision() argument must be between 1 and 21"); |
| 1526 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1527 | return %NumberToPrecision(x, p); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 1531 | // Harmony isFinite. |
| 1532 | function NumberIsFinite(number) { |
| 1533 | return IS_NUMBER(number) && NUMBER_IS_FINITE(number); |
| 1534 | } |
| 1535 | |
| 1536 | |
| 1537 | // Harmony isNaN. |
| 1538 | function NumberIsNaN(number) { |
| 1539 | return IS_NUMBER(number) && NUMBER_IS_NAN(number); |
| 1540 | } |
| 1541 | |
| 1542 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1543 | // ---------------------------------------------------------------------------- |
| 1544 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1545 | function SetUpNumber() { |
| 1546 | %CheckIsBootstrapping(); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1547 | %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1548 | // Set up the constructor property on the Number prototype object. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1549 | %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); |
| 1550 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 1551 | %OptimizeObjectForAddingMultipleProperties($Number, 5); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1552 | // ECMA-262 section 15.7.3.1. |
| 1553 | %SetProperty($Number, |
| 1554 | "MAX_VALUE", |
| 1555 | 1.7976931348623157e+308, |
| 1556 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1557 | |
| 1558 | // ECMA-262 section 15.7.3.2. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1559 | %SetProperty($Number, "MIN_VALUE", 5e-324, |
| 1560 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1561 | |
| 1562 | // ECMA-262 section 15.7.3.3. |
| 1563 | %SetProperty($Number, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1564 | |
| 1565 | // ECMA-262 section 15.7.3.4. |
| 1566 | %SetProperty($Number, |
| 1567 | "NEGATIVE_INFINITY", |
| 1568 | -1/0, |
| 1569 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1570 | |
| 1571 | // ECMA-262 section 15.7.3.5. |
| 1572 | %SetProperty($Number, |
| 1573 | "POSITIVE_INFINITY", |
| 1574 | 1/0, |
| 1575 | DONT_ENUM | DONT_DELETE | READ_ONLY); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1576 | %ToFastProperties($Number); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1577 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1578 | // Set up non-enumerable functions on the Number prototype object. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1579 | InstallFunctions($Number.prototype, DONT_ENUM, $Array( |
| 1580 | "toString", NumberToString, |
| 1581 | "toLocaleString", NumberToLocaleString, |
| 1582 | "valueOf", NumberValueOf, |
| 1583 | "toFixed", NumberToFixed, |
| 1584 | "toExponential", NumberToExponential, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1585 | "toPrecision", NumberToPrecision |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1586 | )); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 1587 | InstallFunctions($Number, DONT_ENUM, $Array( |
| 1588 | "isFinite", NumberIsFinite, |
| 1589 | "isNaN", NumberIsNaN |
| 1590 | )); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1593 | SetUpNumber(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1594 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1595 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1596 | // ---------------------------------------------------------------------------- |
| 1597 | // Function |
| 1598 | |
| 1599 | $Function.prototype.constructor = $Function; |
| 1600 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1601 | function FunctionSourceString(func) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1602 | while (%IsJSFunctionProxy(func)) { |
| 1603 | func = %GetCallTrap(func); |
| 1604 | } |
| 1605 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1606 | if (!IS_FUNCTION(func)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1607 | throw new $TypeError('Function.prototype.toString is not generic'); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1608 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1609 | |
| 1610 | var source = %FunctionGetSourceCode(func); |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1611 | if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1612 | var name = %FunctionGetName(func); |
| 1613 | if (name) { |
| 1614 | // Mimic what KJS does. |
| 1615 | return 'function ' + name + '() { [native code] }'; |
| 1616 | } else { |
| 1617 | return 'function () { [native code] }'; |
| 1618 | } |
| 1619 | } |
| 1620 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1621 | var name = %FunctionNameShouldPrintAsAnonymous(func) |
| 1622 | ? 'anonymous' |
| 1623 | : %FunctionGetName(func); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1624 | return 'function ' + name + source; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1625 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1626 | |
| 1627 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1628 | function FunctionToString() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1629 | return FunctionSourceString(this); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1630 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1631 | |
| 1632 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1633 | // ES5 15.3.4.5 |
| 1634 | function FunctionBind(this_arg) { // Length is 1. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 1635 | if (!IS_SPEC_FUNCTION(this)) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1636 | throw new $TypeError('Bind must be called on a function'); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1637 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1638 | var boundFunction = function () { |
| 1639 | // Poison .arguments and .caller, but is otherwise not detectable. |
| 1640 | "use strict"; |
| 1641 | // This function must not use any object literals (Object, Array, RegExp), |
| 1642 | // since the literals-array is being used to store the bound data. |
| 1643 | if (%_IsConstructCall()) { |
| 1644 | return %NewObjectFromBound(boundFunction); |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 1645 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1646 | var bindings = %BoundFunctionGetBindings(boundFunction); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1647 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1648 | var argc = %_ArgumentsLength(); |
| 1649 | if (argc == 0) { |
| 1650 | return %Apply(bindings[0], bindings[1], bindings, 2, bindings.length - 2); |
| 1651 | } |
| 1652 | if (bindings.length === 2) { |
| 1653 | return %Apply(bindings[0], bindings[1], arguments, 0, argc); |
| 1654 | } |
| 1655 | var bound_argc = bindings.length - 2; |
| 1656 | var argv = new InternalArray(bound_argc + argc); |
| 1657 | for (var i = 0; i < bound_argc; i++) { |
| 1658 | argv[i] = bindings[i + 2]; |
| 1659 | } |
| 1660 | for (var j = 0; j < argc; j++) { |
| 1661 | argv[i++] = %_Arguments(j); |
| 1662 | } |
| 1663 | return %Apply(bindings[0], bindings[1], argv, 0, bound_argc + argc); |
| 1664 | }; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1665 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1666 | %FunctionRemovePrototype(boundFunction); |
| 1667 | var new_length = 0; |
| 1668 | if (%_ClassOf(this) == "Function") { |
| 1669 | // Function or FunctionProxy. |
| 1670 | var old_length = this.length; |
| 1671 | // FunctionProxies might provide a non-UInt32 value. If so, ignore it. |
| 1672 | if ((typeof old_length === "number") && |
| 1673 | ((old_length >>> 0) === old_length)) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1674 | var argc = %_ArgumentsLength(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1675 | if (argc > 0) argc--; // Don't count the thisArg as parameter. |
| 1676 | new_length = old_length - argc; |
| 1677 | if (new_length < 0) new_length = 0; |
| 1678 | } |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1679 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1680 | // This runtime function finds any remaining arguments on the stack, |
| 1681 | // so we don't pass the arguments object. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1682 | var result = %FunctionBindArguments(boundFunction, this, |
| 1683 | this_arg, new_length); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1684 | |
| 1685 | // We already have caller and arguments properties on functions, |
| 1686 | // which are non-configurable. It therefore makes no sence to |
| 1687 | // try to redefine these as defined by the spec. The spec says |
| 1688 | // that bind should make these throw a TypeError if get or set |
| 1689 | // is called and make them non-enumerable and non-configurable. |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 1690 | // To be consistent with our normal functions we leave this as it is. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1691 | // TODO(lrn): Do set these to be thrower. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1692 | return result; |
| 1693 | } |
| 1694 | |
| 1695 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1696 | function NewFunction(arg1) { // length == 1 |
| 1697 | var n = %_ArgumentsLength(); |
| 1698 | var p = ''; |
| 1699 | if (n > 1) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1700 | p = new InternalArray(n - 1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1701 | for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); |
| 1702 | p = Join(p, n - 1, ',', NonStringToString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1703 | // If the formal parameters string include ) - an illegal |
| 1704 | // character - it may make the combined function expression |
| 1705 | // compile. We avoid this problem by checking for this early on. |
| 1706 | if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); |
| 1707 | } |
| 1708 | var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1709 | var source = '(function(' + p + ') {\n' + body + '\n})'; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1710 | |
| 1711 | // The call to SetNewFunctionAttributes will ensure the prototype |
| 1712 | // property of the resulting function is enumerable (ECMA262, 15.3.5.2). |
jkummerow@chromium.org | 78502a9 | 2012-09-06 13:50:42 +0000 | [diff] [blame] | 1713 | var global_receiver = %GlobalReceiver(global); |
| 1714 | var f = %_CallFunction(global_receiver, %CompileString(source)); |
| 1715 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1716 | %FunctionMarkNameShouldPrintAsAnonymous(f); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1717 | return %SetNewFunctionAttributes(f); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1718 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1719 | |
| 1720 | %SetCode($Function, NewFunction); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1721 | |
| 1722 | // ---------------------------------------------------------------------------- |
| 1723 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1724 | function SetUpFunction() { |
| 1725 | %CheckIsBootstrapping(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1726 | InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1727 | "bind", FunctionBind, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1728 | "toString", FunctionToString |
| 1729 | )); |
| 1730 | } |
| 1731 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 1732 | SetUpFunction(); |