Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "accessors.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 31 | #include "ast.h" |
| 32 | #include "deoptimizer.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | #include "execution.h" |
| 34 | #include "factory.h" |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 35 | #include "list-inl.h" |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 36 | #include "safepoint-table.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 37 | #include "scopeinfo.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | |
| 39 | namespace v8 { |
| 40 | namespace internal { |
| 41 | |
| 42 | |
| 43 | template <class C> |
| 44 | static C* FindInPrototypeChain(Object* obj, bool* found_it) { |
| 45 | ASSERT(!*found_it); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 46 | Heap* heap = HEAP; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 47 | while (!Is<C>(obj)) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 48 | if (obj == heap->null_value()) return NULL; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 49 | obj = obj->GetPrototype(); |
| 50 | } |
| 51 | *found_it = true; |
| 52 | return C::cast(obj); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | // Entry point that never should be called. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 57 | MaybeObject* Accessors::IllegalSetter(JSObject*, Object*, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 58 | UNREACHABLE(); |
| 59 | return NULL; |
| 60 | } |
| 61 | |
| 62 | |
| 63 | Object* Accessors::IllegalGetAccessor(Object* object, void*) { |
| 64 | UNREACHABLE(); |
| 65 | return object; |
| 66 | } |
| 67 | |
| 68 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 69 | MaybeObject* Accessors::ReadOnlySetAccessor(JSObject*, Object* value, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 70 | // According to ECMA-262, section 8.6.2.2, page 28, setting |
| 71 | // read-only properties must be silently ignored. |
| 72 | return value; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | // |
| 77 | // Accessors::ArrayLength |
| 78 | // |
| 79 | |
| 80 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 81 | MaybeObject* Accessors::ArrayGetLength(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 82 | // Traverse the prototype chain until we reach an array. |
| 83 | bool found_it = false; |
| 84 | JSArray* holder = FindInPrototypeChain<JSArray>(object, &found_it); |
| 85 | if (!found_it) return Smi::FromInt(0); |
| 86 | return holder->length(); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | // The helper function will 'flatten' Number objects. |
| 91 | Object* Accessors::FlattenNumber(Object* value) { |
| 92 | if (value->IsNumber() || !value->IsJSValue()) return value; |
| 93 | JSValue* wrapper = JSValue::cast(value); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 94 | ASSERT(Isolate::Current()->context()->global_context()->number_function()-> |
| 95 | has_initial_map()); |
| 96 | Map* number_map = Isolate::Current()->context()->global_context()-> |
| 97 | number_function()->initial_map(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 98 | if (wrapper->map() == number_map) return wrapper->value(); |
| 99 | return value; |
| 100 | } |
| 101 | |
| 102 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 103 | MaybeObject* Accessors::ArraySetLength(JSObject* object, Object* value, void*) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 104 | Isolate* isolate = object->GetIsolate(); |
Ben Murdoch | 7d3e7fc | 2011-07-12 16:37:06 +0100 | [diff] [blame] | 105 | |
| 106 | // This means one of the object's prototypes is a JSArray and the |
| 107 | // object does not have a 'length' property. Calling SetProperty |
| 108 | // causes an infinite loop. |
| 109 | if (!object->IsJSArray()) { |
| 110 | return object->SetLocalPropertyIgnoreAttributes( |
| 111 | isolate->heap()->length_symbol(), value, NONE); |
| 112 | } |
| 113 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 114 | value = FlattenNumber(value); |
| 115 | |
| 116 | // Need to call methods that may trigger GC. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 117 | HandleScope scope(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 118 | |
| 119 | // Protect raw pointers. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 120 | Handle<JSObject> object_handle(object, isolate); |
| 121 | Handle<Object> value_handle(value, isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 122 | |
| 123 | bool has_exception; |
| 124 | Handle<Object> uint32_v = Execution::ToUint32(value_handle, &has_exception); |
| 125 | if (has_exception) return Failure::Exception(); |
| 126 | Handle<Object> number_v = Execution::ToNumber(value_handle, &has_exception); |
| 127 | if (has_exception) return Failure::Exception(); |
| 128 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 129 | if (uint32_v->Number() == number_v->Number()) { |
Ben Murdoch | 7d3e7fc | 2011-07-12 16:37:06 +0100 | [diff] [blame] | 130 | return Handle<JSArray>::cast(object_handle)->SetElementsLength(*uint32_v); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 131 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 132 | return isolate->Throw( |
| 133 | *isolate->factory()->NewRangeError("invalid_array_length", |
| 134 | HandleVector<Object>(NULL, 0))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | |
| 138 | const AccessorDescriptor Accessors::ArrayLength = { |
| 139 | ArrayGetLength, |
| 140 | ArraySetLength, |
| 141 | 0 |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | // |
| 146 | // Accessors::StringLength |
| 147 | // |
| 148 | |
| 149 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 150 | MaybeObject* Accessors::StringGetLength(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 151 | Object* value = object; |
| 152 | if (object->IsJSValue()) value = JSValue::cast(object)->value(); |
| 153 | if (value->IsString()) return Smi::FromInt(String::cast(value)->length()); |
| 154 | // If object is not a string we return 0 to be compatible with WebKit. |
| 155 | // Note: Firefox returns the length of ToString(object). |
| 156 | return Smi::FromInt(0); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | const AccessorDescriptor Accessors::StringLength = { |
| 161 | StringGetLength, |
| 162 | IllegalSetter, |
| 163 | 0 |
| 164 | }; |
| 165 | |
| 166 | |
| 167 | // |
| 168 | // Accessors::ScriptSource |
| 169 | // |
| 170 | |
| 171 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 172 | MaybeObject* Accessors::ScriptGetSource(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 173 | Object* script = JSValue::cast(object)->value(); |
| 174 | return Script::cast(script)->source(); |
| 175 | } |
| 176 | |
| 177 | |
| 178 | const AccessorDescriptor Accessors::ScriptSource = { |
| 179 | ScriptGetSource, |
| 180 | IllegalSetter, |
| 181 | 0 |
| 182 | }; |
| 183 | |
| 184 | |
| 185 | // |
| 186 | // Accessors::ScriptName |
| 187 | // |
| 188 | |
| 189 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 190 | MaybeObject* Accessors::ScriptGetName(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 191 | Object* script = JSValue::cast(object)->value(); |
| 192 | return Script::cast(script)->name(); |
| 193 | } |
| 194 | |
| 195 | |
| 196 | const AccessorDescriptor Accessors::ScriptName = { |
| 197 | ScriptGetName, |
| 198 | IllegalSetter, |
| 199 | 0 |
| 200 | }; |
| 201 | |
| 202 | |
| 203 | // |
| 204 | // Accessors::ScriptId |
| 205 | // |
| 206 | |
| 207 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 208 | MaybeObject* Accessors::ScriptGetId(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 209 | Object* script = JSValue::cast(object)->value(); |
| 210 | return Script::cast(script)->id(); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | const AccessorDescriptor Accessors::ScriptId = { |
| 215 | ScriptGetId, |
| 216 | IllegalSetter, |
| 217 | 0 |
| 218 | }; |
| 219 | |
| 220 | |
| 221 | // |
| 222 | // Accessors::ScriptLineOffset |
| 223 | // |
| 224 | |
| 225 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 226 | MaybeObject* Accessors::ScriptGetLineOffset(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 227 | Object* script = JSValue::cast(object)->value(); |
| 228 | return Script::cast(script)->line_offset(); |
| 229 | } |
| 230 | |
| 231 | |
| 232 | const AccessorDescriptor Accessors::ScriptLineOffset = { |
| 233 | ScriptGetLineOffset, |
| 234 | IllegalSetter, |
| 235 | 0 |
| 236 | }; |
| 237 | |
| 238 | |
| 239 | // |
| 240 | // Accessors::ScriptColumnOffset |
| 241 | // |
| 242 | |
| 243 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 244 | MaybeObject* Accessors::ScriptGetColumnOffset(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 245 | Object* script = JSValue::cast(object)->value(); |
| 246 | return Script::cast(script)->column_offset(); |
| 247 | } |
| 248 | |
| 249 | |
| 250 | const AccessorDescriptor Accessors::ScriptColumnOffset = { |
| 251 | ScriptGetColumnOffset, |
| 252 | IllegalSetter, |
| 253 | 0 |
| 254 | }; |
| 255 | |
| 256 | |
| 257 | // |
| 258 | // Accessors::ScriptData |
| 259 | // |
| 260 | |
| 261 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 262 | MaybeObject* Accessors::ScriptGetData(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 263 | Object* script = JSValue::cast(object)->value(); |
| 264 | return Script::cast(script)->data(); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | const AccessorDescriptor Accessors::ScriptData = { |
| 269 | ScriptGetData, |
| 270 | IllegalSetter, |
| 271 | 0 |
| 272 | }; |
| 273 | |
| 274 | |
| 275 | // |
| 276 | // Accessors::ScriptType |
| 277 | // |
| 278 | |
| 279 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 280 | MaybeObject* Accessors::ScriptGetType(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 281 | Object* script = JSValue::cast(object)->value(); |
| 282 | return Script::cast(script)->type(); |
| 283 | } |
| 284 | |
| 285 | |
| 286 | const AccessorDescriptor Accessors::ScriptType = { |
| 287 | ScriptGetType, |
| 288 | IllegalSetter, |
| 289 | 0 |
| 290 | }; |
| 291 | |
| 292 | |
| 293 | // |
| 294 | // Accessors::ScriptCompilationType |
| 295 | // |
| 296 | |
| 297 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 298 | MaybeObject* Accessors::ScriptGetCompilationType(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | Object* script = JSValue::cast(object)->value(); |
| 300 | return Script::cast(script)->compilation_type(); |
| 301 | } |
| 302 | |
| 303 | |
| 304 | const AccessorDescriptor Accessors::ScriptCompilationType = { |
| 305 | ScriptGetCompilationType, |
| 306 | IllegalSetter, |
| 307 | 0 |
| 308 | }; |
| 309 | |
| 310 | |
| 311 | // |
| 312 | // Accessors::ScriptGetLineEnds |
| 313 | // |
| 314 | |
| 315 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 316 | MaybeObject* Accessors::ScriptGetLineEnds(Object* object, void*) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 317 | JSValue* wrapper = JSValue::cast(object); |
| 318 | Isolate* isolate = wrapper->GetIsolate(); |
| 319 | HandleScope scope(isolate); |
| 320 | Handle<Script> script(Script::cast(wrapper->value()), isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 321 | InitScriptLineEnds(script); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 322 | ASSERT(script->line_ends()->IsFixedArray()); |
| 323 | Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 324 | // We do not want anyone to modify this array from JS. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 325 | ASSERT(*line_ends == isolate->heap()->empty_fixed_array() || |
| 326 | line_ends->map() == isolate->heap()->fixed_cow_array_map()); |
| 327 | Handle<JSArray> js_array = |
| 328 | isolate->factory()->NewJSArrayWithElements(line_ends); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 329 | return *js_array; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | |
| 333 | const AccessorDescriptor Accessors::ScriptLineEnds = { |
| 334 | ScriptGetLineEnds, |
| 335 | IllegalSetter, |
| 336 | 0 |
| 337 | }; |
| 338 | |
| 339 | |
| 340 | // |
| 341 | // Accessors::ScriptGetContextData |
| 342 | // |
| 343 | |
| 344 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 345 | MaybeObject* Accessors::ScriptGetContextData(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 346 | Object* script = JSValue::cast(object)->value(); |
| 347 | return Script::cast(script)->context_data(); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | const AccessorDescriptor Accessors::ScriptContextData = { |
| 352 | ScriptGetContextData, |
| 353 | IllegalSetter, |
| 354 | 0 |
| 355 | }; |
| 356 | |
| 357 | |
| 358 | // |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 359 | // Accessors::ScriptGetEvalFromScript |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 360 | // |
| 361 | |
| 362 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 363 | MaybeObject* Accessors::ScriptGetEvalFromScript(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 364 | Object* script = JSValue::cast(object)->value(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 365 | if (!Script::cast(script)->eval_from_shared()->IsUndefined()) { |
| 366 | Handle<SharedFunctionInfo> eval_from_shared( |
| 367 | SharedFunctionInfo::cast(Script::cast(script)->eval_from_shared())); |
| 368 | |
| 369 | if (eval_from_shared->script()->IsScript()) { |
| 370 | Handle<Script> eval_from_script(Script::cast(eval_from_shared->script())); |
| 371 | return *GetScriptWrapper(eval_from_script); |
| 372 | } |
| 373 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 374 | return HEAP->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 378 | const AccessorDescriptor Accessors::ScriptEvalFromScript = { |
| 379 | ScriptGetEvalFromScript, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 380 | IllegalSetter, |
| 381 | 0 |
| 382 | }; |
| 383 | |
| 384 | |
| 385 | // |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 386 | // Accessors::ScriptGetEvalFromScriptPosition |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 387 | // |
| 388 | |
| 389 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 390 | MaybeObject* Accessors::ScriptGetEvalFromScriptPosition(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 391 | HandleScope scope; |
| 392 | Handle<Script> script(Script::cast(JSValue::cast(object)->value())); |
| 393 | |
| 394 | // If this is not a script compiled through eval there is no eval position. |
| 395 | int compilation_type = Smi::cast(script->compilation_type())->value(); |
| 396 | if (compilation_type != Script::COMPILATION_TYPE_EVAL) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 397 | return HEAP->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | // Get the function from where eval was called and find the source position |
| 401 | // from the instruction offset. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 402 | Handle<Code> code(SharedFunctionInfo::cast( |
| 403 | script->eval_from_shared())->code()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 404 | return Smi::FromInt(code->SourcePosition(code->instruction_start() + |
| 405 | script->eval_from_instructions_offset()->value())); |
| 406 | } |
| 407 | |
| 408 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 409 | const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = { |
| 410 | ScriptGetEvalFromScriptPosition, |
| 411 | IllegalSetter, |
| 412 | 0 |
| 413 | }; |
| 414 | |
| 415 | |
| 416 | // |
| 417 | // Accessors::ScriptGetEvalFromFunctionName |
| 418 | // |
| 419 | |
| 420 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 421 | MaybeObject* Accessors::ScriptGetEvalFromFunctionName(Object* object, void*) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 422 | Object* script = JSValue::cast(object)->value(); |
| 423 | Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast( |
| 424 | Script::cast(script)->eval_from_shared())); |
| 425 | |
| 426 | |
| 427 | // Find the name of the function calling eval. |
| 428 | if (!shared->name()->IsUndefined()) { |
| 429 | return shared->name(); |
| 430 | } else { |
| 431 | return shared->inferred_name(); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | |
| 436 | const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = { |
| 437 | ScriptGetEvalFromFunctionName, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 438 | IllegalSetter, |
| 439 | 0 |
| 440 | }; |
| 441 | |
| 442 | |
| 443 | // |
| 444 | // Accessors::FunctionPrototype |
| 445 | // |
| 446 | |
| 447 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 448 | MaybeObject* Accessors::FunctionGetPrototype(Object* object, void*) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 449 | Heap* heap = Isolate::Current()->heap(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 450 | bool found_it = false; |
| 451 | JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 452 | if (!found_it) return heap->undefined_value(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 453 | while (!function->should_have_prototype()) { |
| 454 | found_it = false; |
| 455 | function = FindInPrototypeChain<JSFunction>(object->GetPrototype(), |
| 456 | &found_it); |
| 457 | // There has to be one because we hit the getter. |
| 458 | ASSERT(found_it); |
| 459 | } |
| 460 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 461 | if (!function->has_prototype()) { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 462 | Object* prototype; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 463 | { MaybeObject* maybe_prototype = heap->AllocateFunctionPrototype(function); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 464 | if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
| 465 | } |
| 466 | Object* result; |
| 467 | { MaybeObject* maybe_result = function->SetPrototype(prototype); |
| 468 | if (!maybe_result->ToObject(&result)) return maybe_result; |
| 469 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 470 | } |
| 471 | return function->prototype(); |
| 472 | } |
| 473 | |
| 474 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 475 | MaybeObject* Accessors::FunctionSetPrototype(JSObject* object, |
| 476 | Object* value, |
| 477 | void*) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 478 | Heap* heap = object->GetHeap(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 479 | bool found_it = false; |
| 480 | JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 481 | if (!found_it) return heap->undefined_value(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 482 | if (!function->should_have_prototype()) { |
| 483 | // Since we hit this accessor, object will have no prototype property. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 484 | return object->SetLocalPropertyIgnoreAttributes(heap->prototype_symbol(), |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 485 | value, |
| 486 | NONE); |
| 487 | } |
| 488 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 489 | if (function->has_initial_map()) { |
| 490 | // If the function has allocated the initial map |
| 491 | // replace it with a copy containing the new prototype. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 492 | Object* new_map; |
| 493 | { MaybeObject* maybe_new_map = |
| 494 | function->initial_map()->CopyDropTransitions(); |
| 495 | if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map; |
| 496 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | function->set_initial_map(Map::cast(new_map)); |
| 498 | } |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 499 | Object* prototype; |
| 500 | { MaybeObject* maybe_prototype = function->SetPrototype(value); |
| 501 | if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype; |
| 502 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 503 | ASSERT(function->prototype() == value); |
| 504 | return function; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | const AccessorDescriptor Accessors::FunctionPrototype = { |
| 509 | FunctionGetPrototype, |
| 510 | FunctionSetPrototype, |
| 511 | 0 |
| 512 | }; |
| 513 | |
| 514 | |
| 515 | // |
| 516 | // Accessors::FunctionLength |
| 517 | // |
| 518 | |
| 519 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 520 | MaybeObject* Accessors::FunctionGetLength(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 521 | bool found_it = false; |
| 522 | JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it); |
| 523 | if (!found_it) return Smi::FromInt(0); |
| 524 | // Check if already compiled. |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 525 | if (!function->shared()->is_compiled()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 526 | // If the function isn't compiled yet, the length is not computed |
| 527 | // correctly yet. Compile it now and return the right length. |
| 528 | HandleScope scope; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 529 | Handle<JSFunction> handle(function); |
| 530 | if (!CompileLazy(handle, KEEP_EXCEPTION)) return Failure::Exception(); |
| 531 | return Smi::FromInt(handle->shared()->length()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 532 | } else { |
| 533 | return Smi::FromInt(function->shared()->length()); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
| 538 | const AccessorDescriptor Accessors::FunctionLength = { |
| 539 | FunctionGetLength, |
| 540 | ReadOnlySetAccessor, |
| 541 | 0 |
| 542 | }; |
| 543 | |
| 544 | |
| 545 | // |
| 546 | // Accessors::FunctionName |
| 547 | // |
| 548 | |
| 549 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 550 | MaybeObject* Accessors::FunctionGetName(Object* object, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 551 | bool found_it = false; |
| 552 | JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 553 | if (!found_it) return HEAP->undefined_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 554 | return holder->shared()->name(); |
| 555 | } |
| 556 | |
| 557 | |
| 558 | const AccessorDescriptor Accessors::FunctionName = { |
| 559 | FunctionGetName, |
| 560 | ReadOnlySetAccessor, |
| 561 | 0 |
| 562 | }; |
| 563 | |
| 564 | |
| 565 | // |
| 566 | // Accessors::FunctionArguments |
| 567 | // |
| 568 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 569 | |
| 570 | static MaybeObject* ConstructArgumentsObjectForInlinedFunction( |
| 571 | JavaScriptFrame* frame, |
| 572 | Handle<JSFunction> inlined_function, |
| 573 | int inlined_frame_index) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 574 | Factory* factory = Isolate::Current()->factory(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 575 | int args_count = inlined_function->shared()->formal_parameter_count(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 576 | ScopedVector<SlotRef> args_slots(args_count); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 577 | SlotRef::ComputeSlotMappingForArguments(frame, |
| 578 | inlined_frame_index, |
| 579 | &args_slots); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 580 | Handle<JSObject> arguments = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 581 | factory->NewArgumentsObject(inlined_function, args_count); |
| 582 | Handle<FixedArray> array = factory->NewFixedArray(args_count); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 583 | for (int i = 0; i < args_count; ++i) { |
| 584 | Handle<Object> value = args_slots[i].GetValue(); |
| 585 | array->set(i, *value); |
| 586 | } |
| 587 | arguments->set_elements(*array); |
| 588 | |
| 589 | // Return the freshly allocated arguments object. |
| 590 | return *arguments; |
| 591 | } |
| 592 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 593 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 594 | MaybeObject* Accessors::FunctionGetArguments(Object* object, void*) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 595 | Isolate* isolate = Isolate::Current(); |
| 596 | HandleScope scope(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 597 | bool found_it = false; |
| 598 | JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 599 | if (!found_it) return isolate->heap()->undefined_value(); |
| 600 | Handle<JSFunction> function(holder, isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 601 | |
| 602 | // Find the top invocation of the function by traversing frames. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 603 | List<JSFunction*> functions(2); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 604 | for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 605 | JavaScriptFrame* frame = it.frame(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 606 | frame->GetFunctions(&functions); |
| 607 | for (int i = functions.length() - 1; i >= 0; i--) { |
| 608 | // Skip all frames that aren't invocations of the given function. |
| 609 | if (functions[i] != *function) continue; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 610 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 611 | if (i > 0) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 612 | // The function in question was inlined. Inlined functions have the |
| 613 | // correct number of arguments and no allocated arguments object, so |
| 614 | // we can construct a fresh one by interpreting the function's |
| 615 | // deoptimization input data. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 616 | return ConstructArgumentsObjectForInlinedFunction(frame, function, i); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | if (!frame->is_optimized()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 620 | // If there is an arguments variable in the stack, we return that. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 621 | Handle<SerializedScopeInfo> info(function->shared()->scope_info()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 622 | int index = info->StackSlotIndex(isolate->heap()->arguments_symbol()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 623 | if (index >= 0) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 624 | Handle<Object> arguments(frame->GetExpression(index), isolate); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 625 | if (!arguments->IsArgumentsMarker()) return *arguments; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 626 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 627 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 628 | |
| 629 | // If there is no arguments variable in the stack or we have an |
| 630 | // optimized frame, we find the frame that holds the actual arguments |
| 631 | // passed to the function. |
| 632 | it.AdvanceToArgumentsFrame(); |
| 633 | frame = it.frame(); |
| 634 | |
| 635 | // Get the number of arguments and construct an arguments object |
| 636 | // mirror for the right frame. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 637 | const int length = frame->ComputeParametersCount(); |
| 638 | Handle<JSObject> arguments = isolate->factory()->NewArgumentsObject( |
| 639 | function, length); |
| 640 | Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 641 | |
| 642 | // Copy the parameters to the arguments object. |
| 643 | ASSERT(array->length() == length); |
| 644 | for (int i = 0; i < length; i++) array->set(i, frame->GetParameter(i)); |
| 645 | arguments->set_elements(*array); |
| 646 | |
| 647 | // Return the freshly allocated arguments object. |
| 648 | return *arguments; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 649 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 650 | functions.Rewind(0); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | // No frame corresponding to the given function found. Return null. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 654 | return isolate->heap()->null_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
| 658 | const AccessorDescriptor Accessors::FunctionArguments = { |
| 659 | FunctionGetArguments, |
| 660 | ReadOnlySetAccessor, |
| 661 | 0 |
| 662 | }; |
| 663 | |
| 664 | |
| 665 | // |
| 666 | // Accessors::FunctionCaller |
| 667 | // |
| 668 | |
| 669 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 670 | static MaybeObject* CheckNonStrictCallerOrThrow( |
| 671 | Isolate* isolate, |
| 672 | JSFunction* caller) { |
| 673 | DisableAssertNoAllocation enable_allocation; |
| 674 | if (caller->shared()->strict_mode()) { |
| 675 | return isolate->Throw( |
| 676 | *isolate->factory()->NewTypeError("strict_caller", |
| 677 | HandleVector<Object>(NULL, 0))); |
| 678 | } |
| 679 | return caller; |
| 680 | } |
| 681 | |
| 682 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 683 | class FrameFunctionIterator { |
| 684 | public: |
| 685 | FrameFunctionIterator(Isolate* isolate, const AssertNoAllocation& promise) |
| 686 | : frame_iterator_(isolate), |
| 687 | functions_(2), |
| 688 | index_(0) { |
| 689 | GetFunctions(); |
| 690 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 691 | JSFunction* next() { |
| 692 | if (functions_.length() == 0) return NULL; |
| 693 | JSFunction* next_function = functions_[index_]; |
| 694 | index_--; |
| 695 | if (index_ < 0) { |
| 696 | GetFunctions(); |
| 697 | } |
| 698 | return next_function; |
| 699 | } |
| 700 | |
| 701 | // Iterate through functions until the first occurence of 'function'. |
| 702 | // Returns true if 'function' is found, and false if the iterator ends |
| 703 | // without finding it. |
| 704 | bool Find(JSFunction* function) { |
| 705 | JSFunction* next_function; |
| 706 | do { |
| 707 | next_function = next(); |
| 708 | if (next_function == function) return true; |
| 709 | } while (next_function != NULL); |
| 710 | return false; |
| 711 | } |
| 712 | private: |
| 713 | void GetFunctions() { |
| 714 | functions_.Rewind(0); |
| 715 | if (frame_iterator_.done()) return; |
| 716 | JavaScriptFrame* frame = frame_iterator_.frame(); |
| 717 | frame->GetFunctions(&functions_); |
| 718 | ASSERT(functions_.length() > 0); |
| 719 | frame_iterator_.Advance(); |
| 720 | index_ = functions_.length() - 1; |
| 721 | } |
| 722 | JavaScriptFrameIterator frame_iterator_; |
| 723 | List<JSFunction*> functions_; |
| 724 | int index_; |
| 725 | }; |
| 726 | |
| 727 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 728 | MaybeObject* Accessors::FunctionGetCaller(Object* object, void*) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 729 | Isolate* isolate = Isolate::Current(); |
| 730 | HandleScope scope(isolate); |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 731 | AssertNoAllocation no_alloc; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 732 | bool found_it = false; |
| 733 | JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 734 | if (!found_it) return isolate->heap()->undefined_value(); |
| 735 | Handle<JSFunction> function(holder, isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 736 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 737 | FrameFunctionIterator it(isolate, no_alloc); |
| 738 | |
| 739 | // Find the function from the frames. |
| 740 | if (!it.Find(*function)) { |
| 741 | // No frame corresponding to the given function found. Return null. |
| 742 | return isolate->heap()->null_value(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 745 | // Find previously called non-toplevel function. |
| 746 | JSFunction* caller; |
| 747 | do { |
| 748 | caller = it.next(); |
| 749 | if (caller == NULL) return isolate->heap()->null_value(); |
| 750 | } while (caller->shared()->is_toplevel()); |
| 751 | |
| 752 | // If caller is a built-in function and caller's caller is also built-in, |
| 753 | // use that instead. |
| 754 | JSFunction* potential_caller = caller; |
| 755 | while (potential_caller != NULL && potential_caller->IsBuiltin()) { |
| 756 | caller = potential_caller; |
| 757 | potential_caller = it.next(); |
| 758 | } |
| 759 | |
| 760 | return CheckNonStrictCallerOrThrow(isolate, caller); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | |
| 764 | const AccessorDescriptor Accessors::FunctionCaller = { |
| 765 | FunctionGetCaller, |
| 766 | ReadOnlySetAccessor, |
| 767 | 0 |
| 768 | }; |
| 769 | |
| 770 | |
| 771 | // |
| 772 | // Accessors::ObjectPrototype |
| 773 | // |
| 774 | |
| 775 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 776 | MaybeObject* Accessors::ObjectGetPrototype(Object* receiver, void*) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 777 | Object* current = receiver->GetPrototype(); |
| 778 | while (current->IsJSObject() && |
| 779 | JSObject::cast(current)->map()->is_hidden_prototype()) { |
| 780 | current = current->GetPrototype(); |
| 781 | } |
| 782 | return current; |
| 783 | } |
| 784 | |
| 785 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 786 | MaybeObject* Accessors::ObjectSetPrototype(JSObject* receiver, |
| 787 | Object* value, |
| 788 | void*) { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 789 | const bool skip_hidden_prototypes = true; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 790 | // To be consistent with other Set functions, return the value. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 791 | return receiver->SetPrototype(value, skip_hidden_prototypes); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | |
| 795 | const AccessorDescriptor Accessors::ObjectPrototype = { |
| 796 | ObjectGetPrototype, |
| 797 | ObjectSetPrototype, |
| 798 | 0 |
| 799 | }; |
| 800 | |
| 801 | } } // namespace v8::internal |