blob: 7c21659ebc4d95d5fc5a2a07ba98f9ef356a07c3 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
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"
31#include "execution.h"
32#include "factory.h"
33#include "scopeinfo.h"
34#include "top.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000035
36namespace v8 {
37namespace internal {
38
39
40template <class C>
41static C* FindInPrototypeChain(Object* obj, bool* found_it) {
42 ASSERT(!*found_it);
43 while (!Is<C>(obj)) {
44 if (obj == Heap::null_value()) return NULL;
45 obj = obj->GetPrototype();
46 }
47 *found_it = true;
48 return C::cast(obj);
49}
50
51
52// Entry point that never should be called.
John Reck59135872010-11-02 12:39:01 -070053MaybeObject* Accessors::IllegalSetter(JSObject*, Object*, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +000054 UNREACHABLE();
55 return NULL;
56}
57
58
59Object* Accessors::IllegalGetAccessor(Object* object, void*) {
60 UNREACHABLE();
61 return object;
62}
63
64
John Reck59135872010-11-02 12:39:01 -070065MaybeObject* Accessors::ReadOnlySetAccessor(JSObject*, Object* value, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +000066 // According to ECMA-262, section 8.6.2.2, page 28, setting
67 // read-only properties must be silently ignored.
68 return value;
69}
70
71
72//
73// Accessors::ArrayLength
74//
75
76
John Reck59135872010-11-02 12:39:01 -070077MaybeObject* Accessors::ArrayGetLength(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +000078 // Traverse the prototype chain until we reach an array.
79 bool found_it = false;
80 JSArray* holder = FindInPrototypeChain<JSArray>(object, &found_it);
81 if (!found_it) return Smi::FromInt(0);
82 return holder->length();
83}
84
85
86// The helper function will 'flatten' Number objects.
87Object* Accessors::FlattenNumber(Object* value) {
88 if (value->IsNumber() || !value->IsJSValue()) return value;
89 JSValue* wrapper = JSValue::cast(value);
90 ASSERT(
91 Top::context()->global_context()->number_function()->has_initial_map());
92 Map* number_map =
93 Top::context()->global_context()->number_function()->initial_map();
94 if (wrapper->map() == number_map) return wrapper->value();
95 return value;
96}
97
98
John Reck59135872010-11-02 12:39:01 -070099MaybeObject* Accessors::ArraySetLength(JSObject* object, Object* value, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000100 value = FlattenNumber(value);
101
102 // Need to call methods that may trigger GC.
103 HandleScope scope;
104
105 // Protect raw pointers.
106 Handle<JSObject> object_handle(object);
107 Handle<Object> value_handle(value);
108
109 bool has_exception;
110 Handle<Object> uint32_v = Execution::ToUint32(value_handle, &has_exception);
111 if (has_exception) return Failure::Exception();
112 Handle<Object> number_v = Execution::ToNumber(value_handle, &has_exception);
113 if (has_exception) return Failure::Exception();
114
115 // Restore raw pointers,
116 object = *object_handle;
117 value = *value_handle;
118
119 if (uint32_v->Number() == number_v->Number()) {
120 if (object->IsJSArray()) {
121 return JSArray::cast(object)->SetElementsLength(*uint32_v);
122 } else {
123 // This means one of the object's prototypes is a JSArray and
124 // the object does not have a 'length' property.
125 // Calling SetProperty causes an infinite loop.
126 return object->IgnoreAttributesAndSetLocalProperty(Heap::length_symbol(),
127 value, NONE);
128 }
129 }
130 return Top::Throw(*Factory::NewRangeError("invalid_array_length",
131 HandleVector<Object>(NULL, 0)));
132}
133
134
135const AccessorDescriptor Accessors::ArrayLength = {
136 ArrayGetLength,
137 ArraySetLength,
138 0
139};
140
141
142//
143// Accessors::StringLength
144//
145
146
John Reck59135872010-11-02 12:39:01 -0700147MaybeObject* Accessors::StringGetLength(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000148 Object* value = object;
149 if (object->IsJSValue()) value = JSValue::cast(object)->value();
150 if (value->IsString()) return Smi::FromInt(String::cast(value)->length());
151 // If object is not a string we return 0 to be compatible with WebKit.
152 // Note: Firefox returns the length of ToString(object).
153 return Smi::FromInt(0);
154}
155
156
157const AccessorDescriptor Accessors::StringLength = {
158 StringGetLength,
159 IllegalSetter,
160 0
161};
162
163
164//
165// Accessors::ScriptSource
166//
167
168
John Reck59135872010-11-02 12:39:01 -0700169MaybeObject* Accessors::ScriptGetSource(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000170 Object* script = JSValue::cast(object)->value();
171 return Script::cast(script)->source();
172}
173
174
175const AccessorDescriptor Accessors::ScriptSource = {
176 ScriptGetSource,
177 IllegalSetter,
178 0
179};
180
181
182//
183// Accessors::ScriptName
184//
185
186
John Reck59135872010-11-02 12:39:01 -0700187MaybeObject* Accessors::ScriptGetName(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000188 Object* script = JSValue::cast(object)->value();
189 return Script::cast(script)->name();
190}
191
192
193const AccessorDescriptor Accessors::ScriptName = {
194 ScriptGetName,
195 IllegalSetter,
196 0
197};
198
199
200//
201// Accessors::ScriptId
202//
203
204
John Reck59135872010-11-02 12:39:01 -0700205MaybeObject* Accessors::ScriptGetId(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000206 Object* script = JSValue::cast(object)->value();
207 return Script::cast(script)->id();
208}
209
210
211const AccessorDescriptor Accessors::ScriptId = {
212 ScriptGetId,
213 IllegalSetter,
214 0
215};
216
217
218//
219// Accessors::ScriptLineOffset
220//
221
222
John Reck59135872010-11-02 12:39:01 -0700223MaybeObject* Accessors::ScriptGetLineOffset(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000224 Object* script = JSValue::cast(object)->value();
225 return Script::cast(script)->line_offset();
226}
227
228
229const AccessorDescriptor Accessors::ScriptLineOffset = {
230 ScriptGetLineOffset,
231 IllegalSetter,
232 0
233};
234
235
236//
237// Accessors::ScriptColumnOffset
238//
239
240
John Reck59135872010-11-02 12:39:01 -0700241MaybeObject* Accessors::ScriptGetColumnOffset(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000242 Object* script = JSValue::cast(object)->value();
243 return Script::cast(script)->column_offset();
244}
245
246
247const AccessorDescriptor Accessors::ScriptColumnOffset = {
248 ScriptGetColumnOffset,
249 IllegalSetter,
250 0
251};
252
253
254//
255// Accessors::ScriptData
256//
257
258
John Reck59135872010-11-02 12:39:01 -0700259MaybeObject* Accessors::ScriptGetData(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000260 Object* script = JSValue::cast(object)->value();
261 return Script::cast(script)->data();
262}
263
264
265const AccessorDescriptor Accessors::ScriptData = {
266 ScriptGetData,
267 IllegalSetter,
268 0
269};
270
271
272//
273// Accessors::ScriptType
274//
275
276
John Reck59135872010-11-02 12:39:01 -0700277MaybeObject* Accessors::ScriptGetType(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000278 Object* script = JSValue::cast(object)->value();
279 return Script::cast(script)->type();
280}
281
282
283const AccessorDescriptor Accessors::ScriptType = {
284 ScriptGetType,
285 IllegalSetter,
286 0
287};
288
289
290//
291// Accessors::ScriptCompilationType
292//
293
294
John Reck59135872010-11-02 12:39:01 -0700295MaybeObject* Accessors::ScriptGetCompilationType(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000296 Object* script = JSValue::cast(object)->value();
297 return Script::cast(script)->compilation_type();
298}
299
300
301const AccessorDescriptor Accessors::ScriptCompilationType = {
302 ScriptGetCompilationType,
303 IllegalSetter,
304 0
305};
306
307
308//
309// Accessors::ScriptGetLineEnds
310//
311
312
John Reck59135872010-11-02 12:39:01 -0700313MaybeObject* Accessors::ScriptGetLineEnds(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000314 HandleScope scope;
315 Handle<Script> script(Script::cast(JSValue::cast(object)->value()));
316 InitScriptLineEnds(script);
Steve Blockd0582a62009-12-15 09:54:21 +0000317 ASSERT(script->line_ends()->IsFixedArray());
318 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends()));
319 Handle<FixedArray> copy = Factory::CopyFixedArray(line_ends);
320 Handle<JSArray> js_array = Factory::NewJSArrayWithElements(copy);
321 return *js_array;
Steve Blocka7e24c12009-10-30 11:49:00 +0000322}
323
324
325const AccessorDescriptor Accessors::ScriptLineEnds = {
326 ScriptGetLineEnds,
327 IllegalSetter,
328 0
329};
330
331
332//
333// Accessors::ScriptGetContextData
334//
335
336
John Reck59135872010-11-02 12:39:01 -0700337MaybeObject* Accessors::ScriptGetContextData(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000338 Object* script = JSValue::cast(object)->value();
339 return Script::cast(script)->context_data();
340}
341
342
343const AccessorDescriptor Accessors::ScriptContextData = {
344 ScriptGetContextData,
345 IllegalSetter,
346 0
347};
348
349
350//
Steve Blockd0582a62009-12-15 09:54:21 +0000351// Accessors::ScriptGetEvalFromScript
Steve Blocka7e24c12009-10-30 11:49:00 +0000352//
353
354
John Reck59135872010-11-02 12:39:01 -0700355MaybeObject* Accessors::ScriptGetEvalFromScript(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000356 Object* script = JSValue::cast(object)->value();
Steve Blockd0582a62009-12-15 09:54:21 +0000357 if (!Script::cast(script)->eval_from_shared()->IsUndefined()) {
358 Handle<SharedFunctionInfo> eval_from_shared(
359 SharedFunctionInfo::cast(Script::cast(script)->eval_from_shared()));
360
361 if (eval_from_shared->script()->IsScript()) {
362 Handle<Script> eval_from_script(Script::cast(eval_from_shared->script()));
363 return *GetScriptWrapper(eval_from_script);
364 }
365 }
366 return Heap::undefined_value();
Steve Blocka7e24c12009-10-30 11:49:00 +0000367}
368
369
Steve Blockd0582a62009-12-15 09:54:21 +0000370const AccessorDescriptor Accessors::ScriptEvalFromScript = {
371 ScriptGetEvalFromScript,
Steve Blocka7e24c12009-10-30 11:49:00 +0000372 IllegalSetter,
373 0
374};
375
376
377//
Steve Blockd0582a62009-12-15 09:54:21 +0000378// Accessors::ScriptGetEvalFromScriptPosition
Steve Blocka7e24c12009-10-30 11:49:00 +0000379//
380
381
John Reck59135872010-11-02 12:39:01 -0700382MaybeObject* Accessors::ScriptGetEvalFromScriptPosition(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000383 HandleScope scope;
384 Handle<Script> script(Script::cast(JSValue::cast(object)->value()));
385
386 // If this is not a script compiled through eval there is no eval position.
387 int compilation_type = Smi::cast(script->compilation_type())->value();
388 if (compilation_type != Script::COMPILATION_TYPE_EVAL) {
389 return Heap::undefined_value();
390 }
391
392 // Get the function from where eval was called and find the source position
393 // from the instruction offset.
Steve Blockd0582a62009-12-15 09:54:21 +0000394 Handle<Code> code(SharedFunctionInfo::cast(
395 script->eval_from_shared())->code());
Steve Blocka7e24c12009-10-30 11:49:00 +0000396 return Smi::FromInt(code->SourcePosition(code->instruction_start() +
397 script->eval_from_instructions_offset()->value()));
398}
399
400
Steve Blockd0582a62009-12-15 09:54:21 +0000401const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = {
402 ScriptGetEvalFromScriptPosition,
403 IllegalSetter,
404 0
405};
406
407
408//
409// Accessors::ScriptGetEvalFromFunctionName
410//
411
412
John Reck59135872010-11-02 12:39:01 -0700413MaybeObject* Accessors::ScriptGetEvalFromFunctionName(Object* object, void*) {
Steve Blockd0582a62009-12-15 09:54:21 +0000414 Object* script = JSValue::cast(object)->value();
415 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(
416 Script::cast(script)->eval_from_shared()));
417
418
419 // Find the name of the function calling eval.
420 if (!shared->name()->IsUndefined()) {
421 return shared->name();
422 } else {
423 return shared->inferred_name();
424 }
425}
426
427
428const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = {
429 ScriptGetEvalFromFunctionName,
Steve Blocka7e24c12009-10-30 11:49:00 +0000430 IllegalSetter,
431 0
432};
433
434
435//
436// Accessors::FunctionPrototype
437//
438
439
John Reck59135872010-11-02 12:39:01 -0700440MaybeObject* Accessors::FunctionGetPrototype(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000441 bool found_it = false;
442 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it);
443 if (!found_it) return Heap::undefined_value();
444 if (!function->has_prototype()) {
John Reck59135872010-11-02 12:39:01 -0700445 Object* prototype;
446 { MaybeObject* maybe_prototype = Heap::AllocateFunctionPrototype(function);
447 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype;
448 }
449 Object* result;
450 { MaybeObject* maybe_result = function->SetPrototype(prototype);
451 if (!maybe_result->ToObject(&result)) return maybe_result;
452 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000453 }
454 return function->prototype();
455}
456
457
John Reck59135872010-11-02 12:39:01 -0700458MaybeObject* Accessors::FunctionSetPrototype(JSObject* object,
459 Object* value,
460 void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000461 bool found_it = false;
462 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it);
463 if (!found_it) return Heap::undefined_value();
464 if (function->has_initial_map()) {
465 // If the function has allocated the initial map
466 // replace it with a copy containing the new prototype.
John Reck59135872010-11-02 12:39:01 -0700467 Object* new_map;
468 { MaybeObject* maybe_new_map =
469 function->initial_map()->CopyDropTransitions();
470 if (!maybe_new_map->ToObject(&new_map)) return maybe_new_map;
471 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000472 function->set_initial_map(Map::cast(new_map));
473 }
John Reck59135872010-11-02 12:39:01 -0700474 Object* prototype;
475 { MaybeObject* maybe_prototype = function->SetPrototype(value);
476 if (!maybe_prototype->ToObject(&prototype)) return maybe_prototype;
477 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000478 ASSERT(function->prototype() == value);
479 return function;
480}
481
482
483const AccessorDescriptor Accessors::FunctionPrototype = {
484 FunctionGetPrototype,
485 FunctionSetPrototype,
486 0
487};
488
489
490//
491// Accessors::FunctionLength
492//
493
494
John Reck59135872010-11-02 12:39:01 -0700495MaybeObject* Accessors::FunctionGetLength(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000496 bool found_it = false;
497 JSFunction* function = FindInPrototypeChain<JSFunction>(object, &found_it);
498 if (!found_it) return Smi::FromInt(0);
499 // Check if already compiled.
Iain Merrick75681382010-08-19 15:07:18 +0100500 if (!function->shared()->is_compiled()) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000501 // If the function isn't compiled yet, the length is not computed
502 // correctly yet. Compile it now and return the right length.
503 HandleScope scope;
Leon Clarke4515c472010-02-03 11:58:03 +0000504 Handle<SharedFunctionInfo> shared(function->shared());
505 if (!CompileLazyShared(shared, KEEP_EXCEPTION)) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000506 return Failure::Exception();
507 }
Leon Clarke4515c472010-02-03 11:58:03 +0000508 return Smi::FromInt(shared->length());
Steve Blocka7e24c12009-10-30 11:49:00 +0000509 } else {
510 return Smi::FromInt(function->shared()->length());
511 }
512}
513
514
515const AccessorDescriptor Accessors::FunctionLength = {
516 FunctionGetLength,
517 ReadOnlySetAccessor,
518 0
519};
520
521
522//
523// Accessors::FunctionName
524//
525
526
John Reck59135872010-11-02 12:39:01 -0700527MaybeObject* Accessors::FunctionGetName(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000528 bool found_it = false;
529 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it);
530 if (!found_it) return Heap::undefined_value();
531 return holder->shared()->name();
532}
533
534
535const AccessorDescriptor Accessors::FunctionName = {
536 FunctionGetName,
537 ReadOnlySetAccessor,
538 0
539};
540
541
542//
543// Accessors::FunctionArguments
544//
545
546
John Reck59135872010-11-02 12:39:01 -0700547MaybeObject* Accessors::FunctionGetArguments(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000548 HandleScope scope;
549 bool found_it = false;
550 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it);
551 if (!found_it) return Heap::undefined_value();
552 Handle<JSFunction> function(holder);
553
554 // Find the top invocation of the function by traversing frames.
555 for (JavaScriptFrameIterator it; !it.done(); it.Advance()) {
556 // Skip all frames that aren't invocations of the given function.
557 JavaScriptFrame* frame = it.frame();
558 if (frame->function() != *function) continue;
559
560 // If there is an arguments variable in the stack, we return that.
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100561 int index = function->shared()->scope_info()->
562 StackSlotIndex(Heap::arguments_symbol());
Steve Blocka7e24c12009-10-30 11:49:00 +0000563 if (index >= 0) {
564 Handle<Object> arguments = Handle<Object>(frame->GetExpression(index));
565 if (!arguments->IsTheHole()) return *arguments;
566 }
567
568 // If there isn't an arguments variable in the stack, we need to
569 // find the frame that holds the actual arguments passed to the
570 // function on the stack.
571 it.AdvanceToArgumentsFrame();
572 frame = it.frame();
573
574 // Get the number of arguments and construct an arguments object
575 // mirror for the right frame.
576 const int length = frame->GetProvidedParametersCount();
577 Handle<JSObject> arguments = Factory::NewArgumentsObject(function, length);
578 Handle<FixedArray> array = Factory::NewFixedArray(length);
579
580 // Copy the parameters to the arguments object.
581 ASSERT(array->length() == length);
582 for (int i = 0; i < length; i++) array->set(i, frame->GetParameter(i));
583 arguments->set_elements(*array);
584
585 // Return the freshly allocated arguments object.
586 return *arguments;
587 }
588
589 // No frame corresponding to the given function found. Return null.
590 return Heap::null_value();
591}
592
593
594const AccessorDescriptor Accessors::FunctionArguments = {
595 FunctionGetArguments,
596 ReadOnlySetAccessor,
597 0
598};
599
600
601//
602// Accessors::FunctionCaller
603//
604
605
John Reck59135872010-11-02 12:39:01 -0700606MaybeObject* Accessors::FunctionGetCaller(Object* object, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000607 HandleScope scope;
John Reck59135872010-11-02 12:39:01 -0700608 AssertNoAllocation no_alloc;
Steve Blocka7e24c12009-10-30 11:49:00 +0000609 bool found_it = false;
610 JSFunction* holder = FindInPrototypeChain<JSFunction>(object, &found_it);
611 if (!found_it) return Heap::undefined_value();
612 Handle<JSFunction> function(holder);
613
614 // Find the top invocation of the function by traversing frames.
615 for (JavaScriptFrameIterator it; !it.done(); it.Advance()) {
616 // Skip all frames that aren't invocations of the given function.
617 if (it.frame()->function() != *function) continue;
618 // Once we have found the frame, we need to go to the caller
619 // frame. This may require skipping through a number of top-level
620 // frames, e.g. frames for scripts not functions.
621 while (true) {
622 it.Advance();
623 if (it.done()) return Heap::null_value();
624 JSFunction* caller = JSFunction::cast(it.frame()->function());
625 if (!caller->shared()->is_toplevel()) return caller;
626 }
627 }
628
629 // No frame corresponding to the given function found. Return null.
630 return Heap::null_value();
631}
632
633
634const AccessorDescriptor Accessors::FunctionCaller = {
635 FunctionGetCaller,
636 ReadOnlySetAccessor,
637 0
638};
639
640
641//
642// Accessors::ObjectPrototype
643//
644
645
John Reck59135872010-11-02 12:39:01 -0700646MaybeObject* Accessors::ObjectGetPrototype(Object* receiver, void*) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000647 Object* current = receiver->GetPrototype();
648 while (current->IsJSObject() &&
649 JSObject::cast(current)->map()->is_hidden_prototype()) {
650 current = current->GetPrototype();
651 }
652 return current;
653}
654
655
John Reck59135872010-11-02 12:39:01 -0700656MaybeObject* Accessors::ObjectSetPrototype(JSObject* receiver,
657 Object* value,
658 void*) {
Andrei Popescu402d9372010-02-26 13:31:12 +0000659 const bool skip_hidden_prototypes = true;
Steve Blocka7e24c12009-10-30 11:49:00 +0000660 // To be consistent with other Set functions, return the value.
Andrei Popescu402d9372010-02-26 13:31:12 +0000661 return receiver->SetPrototype(value, skip_hidden_prototypes);
Steve Blocka7e24c12009-10-30 11:49:00 +0000662}
663
664
665const AccessorDescriptor Accessors::ObjectPrototype = {
666 ObjectGetPrototype,
667 ObjectSetPrototype,
668 0
669};
670
671} } // namespace v8::internal