blob: 463a15f6c3b4d650a433f77d988e72539a60aaae [file] [log] [blame]
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001// Copyright 2012 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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 "api.h"
ager@chromium.org18ad94b2009-09-02 08:22:29 +000031#include "arguments.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000032#include "bootstrapper.h"
33#include "builtins.h"
machenbach@chromium.orgc1789ee2013-07-05 07:09:57 +000034#include "cpu-profiler.h"
erik.corry@gmail.com0511e242011-01-19 11:11:08 +000035#include "gdb-jit.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036#include "ic-inl.h"
ulan@chromium.org6ff65142012-03-21 09:52:17 +000037#include "heap-profiler.h"
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000038#include "mark-compact.h"
yangguo@chromium.org46839fb2012-08-28 09:06:19 +000039#include "stub-cache.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000040#include "vm-state-inl.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000041
kasperl@chromium.org71affb52009-05-26 05:44:31 +000042namespace v8 {
43namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000044
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000045namespace {
46
47// Arguments object passed to C++ builtins.
48template <BuiltinExtraArguments extra_args>
49class BuiltinArguments : public Arguments {
50 public:
51 BuiltinArguments(int length, Object** arguments)
52 : Arguments(length, arguments) { }
53
54 Object*& operator[] (int index) {
55 ASSERT(index < length());
56 return Arguments::operator[](index);
57 }
58
59 template <class S> Handle<S> at(int index) {
60 ASSERT(index < length());
61 return Arguments::at<S>(index);
62 }
63
64 Handle<Object> receiver() {
65 return Arguments::at<Object>(0);
66 }
67
68 Handle<JSFunction> called_function() {
69 STATIC_ASSERT(extra_args == NEEDS_CALLED_FUNCTION);
70 return Arguments::at<JSFunction>(Arguments::length() - 1);
71 }
72
73 // Gets the total number of arguments including the receiver (but
74 // excluding extra arguments).
75 int length() const {
76 STATIC_ASSERT(extra_args == NO_EXTRA_ARGUMENTS);
77 return Arguments::length();
78 }
79
80#ifdef DEBUG
81 void Verify() {
82 // Check we have at least the receiver.
83 ASSERT(Arguments::length() >= 1);
84 }
85#endif
86};
87
88
89// Specialize BuiltinArguments for the called function extra argument.
90
91template <>
92int BuiltinArguments<NEEDS_CALLED_FUNCTION>::length() const {
93 return Arguments::length() - 1;
94}
95
96#ifdef DEBUG
97template <>
98void BuiltinArguments<NEEDS_CALLED_FUNCTION>::Verify() {
99 // Check we have at least the receiver and the called function.
100 ASSERT(Arguments::length() >= 2);
101 // Make sure cast to JSFunction succeeds.
102 called_function();
103}
104#endif
105
106
107#define DEF_ARG_TYPE(name, spec) \
108 typedef BuiltinArguments<spec> name##ArgumentsType;
109BUILTIN_LIST_C(DEF_ARG_TYPE)
110#undef DEF_ARG_TYPE
111
112} // namespace
113
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000114// ----------------------------------------------------------------------------
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000115// Support macro for defining builtins in C++.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000116// ----------------------------------------------------------------------------
117//
118// A builtin function is defined by writing:
119//
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000120// BUILTIN(name) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000121// ...
122// }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000123//
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000124// In the body of the builtin function the arguments can be accessed
125// through the BuiltinArguments object args.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000126
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000127#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000128
danno@chromium.orgf005df62013-04-30 16:36:45 +0000129#define BUILTIN(name) \
130 MUST_USE_RESULT static MaybeObject* Builtin_Impl_##name( \
131 name##ArgumentsType args, Isolate* isolate); \
132 MUST_USE_RESULT static MaybeObject* Builtin_##name( \
133 int args_length, Object** args_object, Isolate* isolate) { \
134 name##ArgumentsType args(args_length, args_object); \
danno@chromium.orgf005df62013-04-30 16:36:45 +0000135 args.Verify(); \
136 return Builtin_Impl_##name(args, isolate); \
137 } \
138 MUST_USE_RESULT static MaybeObject* Builtin_Impl_##name( \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000139 name##ArgumentsType args, Isolate* isolate)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000140
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000141#else // For release mode.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000142
danno@chromium.orgf005df62013-04-30 16:36:45 +0000143#define BUILTIN(name) \
144 static MaybeObject* Builtin_impl##name( \
145 name##ArgumentsType args, Isolate* isolate); \
146 static MaybeObject* Builtin_##name( \
147 int args_length, Object** args_object, Isolate* isolate) { \
148 name##ArgumentsType args(args_length, args_object); \
149 return Builtin_impl##name(args, isolate); \
150 } \
151 static MaybeObject* Builtin_impl##name( \
152 name##ArgumentsType args, Isolate* isolate)
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000153#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000154
155
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000156#ifdef DEBUG
machenbach@chromium.orgafbdadc2013-12-09 16:12:18 +0000157static inline bool CalledAsConstructor(Isolate* isolate) {
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000158 // Calculate the result using a full stack frame iterator and check
159 // that the state of the stack is as we assume it to be in the
160 // code below.
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +0000161 StackFrameIterator it(isolate);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000162 ASSERT(it.frame()->is_exit());
163 it.Advance();
164 StackFrame* frame = it.frame();
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000165 bool reference_result = frame->is_construct();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000166 Address fp = Isolate::c_entry_fp(isolate->thread_local_top());
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000167 // Because we know fp points to an exit frame we can use the relevant
168 // part of ExitFrame::ComputeCallerState directly.
169 const int kCallerOffset = ExitFrameConstants::kCallerFPOffset;
170 Address caller_fp = Memory::Address_at(fp + kCallerOffset);
171 // This inlines the part of StackFrame::ComputeType that grabs the
172 // type of the current frame. Note that StackFrame::ComputeType
173 // has been specialized for each architecture so if any one of them
174 // changes this code has to be changed as well.
175 const int kMarkerOffset = StandardFrameConstants::kMarkerOffset;
176 const Smi* kConstructMarker = Smi::FromInt(StackFrame::CONSTRUCT);
177 Object* marker = Memory::Object_at(caller_fp + kMarkerOffset);
178 bool result = (marker == kConstructMarker);
179 ASSERT_EQ(result, reference_result);
180 return result;
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000181}
machenbach@chromium.orgafbdadc2013-12-09 16:12:18 +0000182#endif
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000183
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +0000184
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000185// ----------------------------------------------------------------------------
186
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000187BUILTIN(Illegal) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000188 UNREACHABLE();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000189 return isolate->heap()->undefined_value(); // Make compiler happy.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000190}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000191
192
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000193BUILTIN(EmptyFunction) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000194 return isolate->heap()->undefined_value();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000195}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000196
197
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000198static void MoveDoubleElements(FixedDoubleArray* dst,
199 int dst_index,
200 FixedDoubleArray* src,
201 int src_index,
202 int len) {
203 if (len == 0) return;
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000204 OS::MemMove(dst->data_start() + dst_index,
205 src->data_start() + src_index,
206 len * kDoubleSize);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000207}
208
209
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000210static FixedArrayBase* LeftTrimFixedArray(Heap* heap,
211 FixedArrayBase* elms,
212 int to_trim) {
machenbach@chromium.org63a7c9f2014-04-01 00:04:36 +0000213 ASSERT(heap->CanMoveObjectStart(elms));
214
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000215 Map* map = elms->map();
216 int entry_size;
217 if (elms->IsFixedArray()) {
218 entry_size = kPointerSize;
219 } else {
220 entry_size = kDoubleSize;
221 }
hpayer@chromium.orgc5d49712013-09-11 08:25:48 +0000222 ASSERT(elms->map() != heap->fixed_cow_array_map());
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000223 // For now this trick is only applied to fixed arrays in new and paged space.
lrn@chromium.org25156de2010-04-06 13:10:27 +0000224 // In large object space the object's start must coincide with chunk
225 // and thus the trick is just not applicable.
hpayer@chromium.orgc5d49712013-09-11 08:25:48 +0000226 ASSERT(!heap->lo_space()->Contains(elms));
lrn@chromium.org25156de2010-04-06 13:10:27 +0000227
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000228 STATIC_ASSERT(FixedArrayBase::kMapOffset == 0);
229 STATIC_ASSERT(FixedArrayBase::kLengthOffset == kPointerSize);
230 STATIC_ASSERT(FixedArrayBase::kHeaderSize == 2 * kPointerSize);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000231
232 Object** former_start = HeapObject::RawField(elms, 0);
233
234 const int len = elms->length();
235
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000236 if (to_trim * entry_size > FixedArrayBase::kHeaderSize &&
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000237 elms->IsFixedArray() &&
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000238 !heap->new_space()->Contains(elms)) {
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000239 // If we are doing a big trim in old space then we zap the space that was
240 // formerly part of the array so that the GC (aided by the card-based
241 // remembered set) won't find pointers to new-space there.
242 Object** zap = reinterpret_cast<Object**>(elms->address());
243 zap++; // Header of filler must be at least one word so skip that.
244 for (int i = 1; i < to_trim; i++) {
245 *zap++ = Smi::FromInt(0);
246 }
247 }
lrn@chromium.org25156de2010-04-06 13:10:27 +0000248 // Technically in new space this write might be omitted (except for
249 // debug mode which iterates through the heap), but to play safer
250 // we still do it.
machenbach@chromium.org63a7c9f2014-04-01 00:04:36 +0000251 // Since left trimming is only performed on pages which are not concurrently
252 // swept creating a filler object does not require synchronization.
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000253 heap->CreateFillerObjectAt(elms->address(), to_trim * entry_size);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000254
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000255 int new_start_index = to_trim * (entry_size / kPointerSize);
256 former_start[new_start_index] = map;
257 former_start[new_start_index + 1] = Smi::FromInt(len - to_trim);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000258
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000259 // Maintain marking consistency for HeapObjectIterator and
260 // IncrementalMarking.
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000261 int size_delta = to_trim * entry_size;
machenbach@chromium.org56971442014-03-19 13:13:40 +0000262 Address new_start = elms->address() + size_delta;
263 heap->marking()->TransferMark(elms->address(), new_start);
264 heap->AdjustLiveBytes(new_start, -size_delta, Heap::FROM_MUTATOR);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000265
machenbach@chromium.org56971442014-03-19 13:13:40 +0000266 FixedArrayBase* new_elms =
267 FixedArrayBase::cast(HeapObject::FromAddress(new_start));
mstarzinger@chromium.org2ed0d022013-10-17 08:06:21 +0000268 HeapProfiler* profiler = heap->isolate()->heap_profiler();
yangguo@chromium.orgcc536052013-11-29 11:43:20 +0000269 if (profiler->is_tracking_object_moves()) {
mstarzinger@chromium.org2ed0d022013-10-17 08:06:21 +0000270 profiler->ObjectMoveEvent(elms->address(),
bmeurer@chromium.org0fdb2a62013-10-21 07:19:36 +0000271 new_elms->address(),
272 new_elms->Size());
mstarzinger@chromium.org2ed0d022013-10-17 08:06:21 +0000273 }
bmeurer@chromium.org0fdb2a62013-10-21 07:19:36 +0000274 return new_elms;
lrn@chromium.org25156de2010-04-06 13:10:27 +0000275}
276
277
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000278static bool ArrayPrototypeHasNoElements(Heap* heap,
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000279 Context* native_context,
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000280 JSObject* array_proto) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000281 DisallowHeapAllocation no_gc;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000282 // This method depends on non writability of Object and Array prototype
283 // fields.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000284 if (array_proto->elements() != heap->empty_fixed_array()) return false;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000285 // Object.prototype
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +0000286 Object* proto = array_proto->GetPrototype();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000287 if (proto == heap->null_value()) return false;
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +0000288 array_proto = JSObject::cast(proto);
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000289 if (array_proto != native_context->initial_object_prototype()) return false;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000290 if (array_proto->elements() != heap->empty_fixed_array()) return false;
danno@chromium.org40cb8782011-05-25 07:58:50 +0000291 return array_proto->GetPrototype()->IsNull();
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000292}
293
294
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000295// Returns empty handle if not applicable.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000296MUST_USE_RESULT
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000297static inline MaybeHandle<FixedArrayBase> EnsureJSArrayWithWritableFastElements(
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000298 Isolate* isolate,
299 Handle<Object> receiver,
300 Arguments* args,
301 int first_added_arg) {
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000302 if (!receiver->IsJSArray()) return MaybeHandle<FixedArrayBase>();
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000303 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000304 if (array->map()->is_observed()) return MaybeHandle<FixedArrayBase>();
305 if (!array->map()->is_extensible()) return MaybeHandle<FixedArrayBase>();
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000306 Handle<FixedArrayBase> elms(array->elements(), isolate);
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000307 Heap* heap = isolate->heap();
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000308 Map* map = elms->map();
309 if (map == heap->fixed_array_map()) {
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000310 if (args == NULL || array->HasFastObjectElements()) return elms;
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000311 } else if (map == heap->fixed_cow_array_map()) {
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000312 elms = JSObject::EnsureWritableFastElements(array);
313 if (args == NULL || array->HasFastObjectElements()) return elms;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000314 } else if (map == heap->fixed_double_array_map()) {
315 if (args == NULL) return elms;
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000316 } else {
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000317 return MaybeHandle<FixedArrayBase>();
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000318 }
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000319
320 // Need to ensure that the arguments passed in args can be contained in
321 // the array.
322 int args_length = args->length();
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000323 if (first_added_arg >= args_length) return handle(array->elements(), isolate);
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000324
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000325 ElementsKind origin_kind = array->map()->elements_kind();
326 ASSERT(!IsFastObjectElementsKind(origin_kind));
327 ElementsKind target_kind = origin_kind;
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000328 {
329 DisallowHeapAllocation no_gc;
330 int arg_count = args->length() - first_added_arg;
331 Object** arguments = args->arguments() - first_added_arg - (arg_count - 1);
332 for (int i = 0; i < arg_count; i++) {
333 Object* arg = arguments[i];
334 if (arg->IsHeapObject()) {
335 if (arg->IsHeapNumber()) {
336 target_kind = FAST_DOUBLE_ELEMENTS;
337 } else {
338 target_kind = FAST_ELEMENTS;
339 break;
340 }
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000341 }
342 }
343 }
344 if (target_kind != origin_kind) {
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000345 JSObject::TransitionElementsKind(array, target_kind);
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000346 return handle(array->elements(), isolate);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000347 }
348 return elms;
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000349}
350
351
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000352static inline bool IsJSArrayFastElementMovingAllowed(Heap* heap,
353 JSArray* receiver) {
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +0000354 if (!FLAG_clever_optimizations) return false;
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000355 DisallowHeapAllocation no_gc;
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000356 Context* native_context = heap->isolate()->context()->native_context();
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000357 JSObject* array_proto =
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000358 JSObject::cast(native_context->array_function()->prototype());
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000359 return receiver->GetPrototype() == array_proto &&
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000360 ArrayPrototypeHasNoElements(heap, native_context, array_proto);
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000361}
362
363
lrn@chromium.org303ada72010-10-27 09:33:13 +0000364MUST_USE_RESULT static MaybeObject* CallJsBuiltin(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000365 Isolate* isolate,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000366 const char* name,
367 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000368 HandleScope handleScope(isolate);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000369
370 Handle<Object> js_builtin =
yangguo@chromium.org46839fb2012-08-28 09:06:19 +0000371 GetProperty(Handle<JSObject>(isolate->native_context()->builtins()),
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000372 name);
373 Handle<JSFunction> function = Handle<JSFunction>::cast(js_builtin);
374 int argc = args.length() - 1;
375 ScopedVector<Handle<Object> > argv(argc);
376 for (int i = 0; i < argc; ++i) {
377 argv[i] = args.at<Object>(i + 1);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000378 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000379 bool pending_exception;
jkummerow@chromium.org2c9426b2013-09-05 16:31:13 +0000380 Handle<Object> result = Execution::Call(isolate,
381 function,
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000382 args.receiver(),
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000383 argc,
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000384 argv.start(),
385 &pending_exception);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000386 if (pending_exception) return Failure::Exception();
387 return *result;
388}
389
390
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000391BUILTIN(ArrayPush) {
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000392 HandleScope scope(isolate);
393 Handle<Object> receiver = args.receiver();
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000394 MaybeHandle<FixedArrayBase> maybe_elms_obj =
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000395 EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 1);
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000396 Handle<FixedArrayBase> elms_obj;
397 if (!maybe_elms_obj.ToHandle(&elms_obj)) {
398 return CallJsBuiltin(isolate, "ArrayPush", args);
399 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000400
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000401 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +0000402 ASSERT(!array->map()->is_observed());
403
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000404 ElementsKind kind = array->GetElementsKind();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000405
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000406 if (IsFastSmiOrObjectElementsKind(kind)) {
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000407 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000408
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000409 int len = Smi::cast(array->length())->value();
410 int to_add = args.length() - 1;
411 if (to_add == 0) {
412 return Smi::FromInt(len);
lrn@chromium.org303ada72010-10-27 09:33:13 +0000413 }
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000414 // Currently fixed arrays cannot grow too big, so
415 // we should never hit this case.
416 ASSERT(to_add <= (Smi::kMaxValue - len));
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000417
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000418 int new_length = len + to_add;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000419
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000420 if (new_length > elms->length()) {
421 // New backing storage is needed.
422 int capacity = new_length + (new_length >> 1) + 16;
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000423 Handle<FixedArray> new_elms =
424 isolate->factory()->NewUninitializedFixedArray(capacity);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000425
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000426 ElementsAccessor* accessor = array->GetElementsAccessor();
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000427 accessor->CopyElements(
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000428 elms_obj, 0, kind, new_elms, 0,
429 ElementsAccessor::kCopyToEndAndInitializeToHole);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000430
431 elms = new_elms;
432 }
433
434 // Add the provided values.
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000435 DisallowHeapAllocation no_gc;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000436 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
437 for (int index = 0; index < to_add; index++) {
438 elms->set(index + len, args[index + 1], mode);
439 }
440
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000441 if (*elms != array->elements()) {
442 array->set_elements(*elms);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000443 }
444
445 // Set the length.
446 array->set_length(Smi::FromInt(new_length));
447 return Smi::FromInt(new_length);
448 } else {
449 int len = Smi::cast(array->length())->value();
450 int elms_len = elms_obj->length();
451
452 int to_add = args.length() - 1;
453 if (to_add == 0) {
454 return Smi::FromInt(len);
455 }
456 // Currently fixed arrays cannot grow too big, so
457 // we should never hit this case.
458 ASSERT(to_add <= (Smi::kMaxValue - len));
459
460 int new_length = len + to_add;
461
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000462 Handle<FixedDoubleArray> new_elms;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000463
464 if (new_length > elms_len) {
465 // New backing storage is needed.
466 int capacity = new_length + (new_length >> 1) + 16;
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000467 new_elms = isolate->factory()->NewFixedDoubleArray(capacity);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000468
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000469 ElementsAccessor* accessor = array->GetElementsAccessor();
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000470 accessor->CopyElements(
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000471 elms_obj, 0, kind, new_elms, 0,
472 ElementsAccessor::kCopyToEndAndInitializeToHole);
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000473
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000474 } else {
475 // to_add is > 0 and new_length <= elms_len, so elms_obj cannot be the
476 // empty_fixed_array.
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000477 new_elms = Handle<FixedDoubleArray>::cast(elms_obj);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000478 }
479
480 // Add the provided values.
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000481 DisallowHeapAllocation no_gc;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000482 int index;
483 for (index = 0; index < to_add; index++) {
484 Object* arg = args[index + 1];
485 new_elms->set(index + len, arg->Number());
486 }
487
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000488 if (*new_elms != array->elements()) {
489 array->set_elements(*new_elms);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000490 }
491
492 // Set the length.
493 array->set_length(Smi::FromInt(new_length));
494 return Smi::FromInt(new_length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000495 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000496}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000497
498
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000499BUILTIN(ArrayPop) {
machenbach@chromium.org69f64b12014-03-20 01:04:55 +0000500 HandleScope scope(isolate);
501 Handle<Object> receiver = args.receiver();
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000502 MaybeHandle<FixedArrayBase> maybe_elms_obj =
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000503 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0);
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000504 Handle<FixedArrayBase> elms_obj;
505 if (!maybe_elms_obj.ToHandle(&elms_obj)) {
506 return CallJsBuiltin(isolate, "ArrayPop", args);
507 }
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000508
machenbach@chromium.org69f64b12014-03-20 01:04:55 +0000509 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +0000510 ASSERT(!array->map()->is_observed());
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +0000511
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000512 int len = Smi::cast(array->length())->value();
machenbach@chromium.org69f64b12014-03-20 01:04:55 +0000513 if (len == 0) return isolate->heap()->undefined_value();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000514
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000515 ElementsAccessor* accessor = array->GetElementsAccessor();
516 int new_length = len - 1;
machenbach@chromium.org69f64b12014-03-20 01:04:55 +0000517 Handle<Object> element;
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000518 if (accessor->HasElement(array, array, new_length, elms_obj)) {
machenbach@chromium.orgb5ed9302014-03-25 13:44:35 +0000519 element = accessor->Get(
520 array, array, new_length, elms_obj);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000521 } else {
machenbach@chromium.org4452a492014-03-18 13:03:00 +0000522 Handle<Object> proto(array->GetPrototype(), isolate);
machenbach@chromium.org69f64b12014-03-20 01:04:55 +0000523 element = Object::GetElement(isolate, proto, len - 1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000524 }
machenbach@chromium.org69f64b12014-03-20 01:04:55 +0000525 RETURN_IF_EMPTY_HANDLE(isolate, element);
526 RETURN_IF_EMPTY_HANDLE(isolate,
527 accessor->SetLength(
528 array, handle(Smi::FromInt(new_length), isolate)));
529 return *element;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000530}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000531
532
ager@chromium.org5c838252010-02-19 08:53:10 +0000533BUILTIN(ArrayShift) {
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000534 HandleScope scope(isolate);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000535 Heap* heap = isolate->heap();
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000536 Handle<Object> receiver = args.receiver();
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000537 MaybeHandle<FixedArrayBase> maybe_elms_obj =
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000538 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0);
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000539 Handle<FixedArrayBase> elms_obj;
540 if (!maybe_elms_obj.ToHandle(&elms_obj) ||
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000541 !IsJSArrayFastElementMovingAllowed(heap,
542 *Handle<JSArray>::cast(receiver))) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000543 return CallJsBuiltin(isolate, "ArrayShift", args);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000544 }
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000545 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +0000546 ASSERT(!array->map()->is_observed());
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +0000547
ager@chromium.org5c838252010-02-19 08:53:10 +0000548 int len = Smi::cast(array->length())->value();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000549 if (len == 0) return heap->undefined_value();
ager@chromium.org5c838252010-02-19 08:53:10 +0000550
ager@chromium.org5c838252010-02-19 08:53:10 +0000551 // Get first element
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000552 ElementsAccessor* accessor = array->GetElementsAccessor();
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000553 Handle<Object> first = accessor->Get(receiver, array, 0, elms_obj);
machenbach@chromium.orgb5ed9302014-03-25 13:44:35 +0000554 RETURN_IF_EMPTY_HANDLE(isolate, first);
ager@chromium.org5c838252010-02-19 08:53:10 +0000555 if (first->IsTheHole()) {
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000556 first = isolate->factory()->undefined_value();
ager@chromium.org5c838252010-02-19 08:53:10 +0000557 }
558
machenbach@chromium.org63a7c9f2014-04-01 00:04:36 +0000559 if (heap->CanMoveObjectStart(*elms_obj)) {
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000560 array->set_elements(LeftTrimFixedArray(heap, *elms_obj, 1));
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000561 } else {
562 // Shift the elements.
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000563 if (elms_obj->IsFixedArray()) {
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000564 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000565 DisallowHeapAllocation no_gc;
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000566 heap->MoveElements(*elms, 0, 1, len - 1);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000567 elms->set(len - 1, heap->the_hole_value());
568 } else {
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000569 Handle<FixedDoubleArray> elms = Handle<FixedDoubleArray>::cast(elms_obj);
570 MoveDoubleElements(*elms, 0, *elms, 1, len - 1);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000571 elms->set_the_hole(len - 1);
572 }
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000573 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000574
575 // Set the length.
576 array->set_length(Smi::FromInt(len - 1));
577
machenbach@chromium.org7010a2d2014-03-20 15:46:12 +0000578 return *first;
ager@chromium.org5c838252010-02-19 08:53:10 +0000579}
580
581
582BUILTIN(ArrayUnshift) {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000583 HandleScope scope(isolate);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000584 Heap* heap = isolate->heap();
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000585 Handle<Object> receiver = args.receiver();
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000586 MaybeHandle<FixedArrayBase> maybe_elms_obj =
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000587 EnsureJSArrayWithWritableFastElements(isolate, receiver, NULL, 0);
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000588 Handle<FixedArrayBase> elms_obj;
589 if (!maybe_elms_obj.ToHandle(&elms_obj) ||
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000590 !IsJSArrayFastElementMovingAllowed(heap,
591 *Handle<JSArray>::cast(receiver))) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000592 return CallJsBuiltin(isolate, "ArrayUnshift", args);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000593 }
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000594 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +0000595 ASSERT(!array->map()->is_observed());
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000596 if (!array->HasFastSmiOrObjectElements()) {
597 return CallJsBuiltin(isolate, "ArrayUnshift", args);
598 }
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000599 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
ager@chromium.org5c838252010-02-19 08:53:10 +0000600
601 int len = Smi::cast(array->length())->value();
602 int to_add = args.length() - 1;
ager@chromium.org5c838252010-02-19 08:53:10 +0000603 int new_length = len + to_add;
604 // Currently fixed arrays cannot grow too big, so
605 // we should never hit this case.
606 ASSERT(to_add <= (Smi::kMaxValue - len));
607
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000608 JSObject::EnsureCanContainElements(array, &args, 1, to_add,
609 DONT_ALLOW_DOUBLE_ELEMENTS);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000610
ager@chromium.org5c838252010-02-19 08:53:10 +0000611 if (new_length > elms->length()) {
612 // New backing storage is needed.
613 int capacity = new_length + (new_length >> 1) + 16;
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000614 Handle<FixedArray> new_elms =
615 isolate->factory()->NewUninitializedFixedArray(capacity);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000616
svenpanne@chromium.org83130cf2012-11-30 10:13:25 +0000617 ElementsKind kind = array->GetElementsKind();
618 ElementsAccessor* accessor = array->GetElementsAccessor();
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000619 accessor->CopyElements(
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000620 elms, 0, kind, new_elms, to_add,
621 ElementsAccessor::kCopyToEndAndInitializeToHole);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000622
ager@chromium.org5c838252010-02-19 08:53:10 +0000623 elms = new_elms;
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000624 array->set_elements(*elms);
ager@chromium.org5c838252010-02-19 08:53:10 +0000625 } else {
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000626 DisallowHeapAllocation no_gc;
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000627 heap->MoveElements(*elms, to_add, 0, len);
ager@chromium.org5c838252010-02-19 08:53:10 +0000628 }
629
630 // Add the provided values.
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000631 DisallowHeapAllocation no_gc;
ager@chromium.org5c838252010-02-19 08:53:10 +0000632 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
633 for (int i = 0; i < to_add; i++) {
634 elms->set(i, args[i + 1], mode);
635 }
636
637 // Set the length.
638 array->set_length(Smi::FromInt(new_length));
639 return Smi::FromInt(new_length);
640}
641
642
ager@chromium.org5c838252010-02-19 08:53:10 +0000643BUILTIN(ArraySlice) {
machenbach@chromium.orgc85dc102014-03-28 01:04:39 +0000644 HandleScope scope(isolate);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000645 Heap* heap = isolate->heap();
machenbach@chromium.orgc85dc102014-03-28 01:04:39 +0000646 Handle<Object> receiver = args.receiver();
whesse@chromium.org023421e2010-12-21 12:19:12 +0000647 int len = -1;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000648 int relative_start = 0;
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000649 int relative_end = 0;
650 {
651 DisallowHeapAllocation no_gc;
652 if (receiver->IsJSArray()) {
653 JSArray* array = JSArray::cast(*receiver);
654 if (!IsJSArrayFastElementMovingAllowed(heap, array)) {
655 AllowHeapAllocation allow_allocation;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000656 return CallJsBuiltin(isolate, "ArraySlice", args);
657 }
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000658
659 if (!array->HasFastElements()) {
660 AllowHeapAllocation allow_allocation;
661 return CallJsBuiltin(isolate, "ArraySlice", args);
662 }
663
664 len = Smi::cast(array->length())->value();
665 } else {
666 // Array.slice(arguments, ...) is quite a common idiom (notably more
667 // than 50% of invocations in Web apps). Treat it in C++ as well.
668 Map* arguments_map = isolate->context()->native_context()->
669 sloppy_arguments_boilerplate()->map();
670
671 bool is_arguments_object_with_fast_elements =
672 receiver->IsJSObject() &&
673 JSObject::cast(*receiver)->map() == arguments_map;
674 if (!is_arguments_object_with_fast_elements) {
675 AllowHeapAllocation allow_allocation;
676 return CallJsBuiltin(isolate, "ArraySlice", args);
677 }
678 JSObject* object = JSObject::cast(*receiver);
679
680 if (!object->HasFastElements()) {
681 AllowHeapAllocation allow_allocation;
682 return CallJsBuiltin(isolate, "ArraySlice", args);
683 }
684
685 Object* len_obj = object->InObjectPropertyAt(Heap::kArgumentsLengthIndex);
686 if (!len_obj->IsSmi()) {
687 AllowHeapAllocation allow_allocation;
688 return CallJsBuiltin(isolate, "ArraySlice", args);
689 }
690 len = Smi::cast(len_obj)->value();
691 if (len > object->elements()->length()) {
692 AllowHeapAllocation allow_allocation;
693 return CallJsBuiltin(isolate, "ArraySlice", args);
694 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000695 }
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000696
697 ASSERT(len >= 0);
698 int n_arguments = args.length() - 1;
699
700 // Note carefully choosen defaults---if argument is missing,
701 // it's undefined which gets converted to 0 for relative_start
702 // and to len for relative_end.
703 relative_start = 0;
704 relative_end = len;
705 if (n_arguments > 0) {
706 Object* arg1 = args[1];
707 if (arg1->IsSmi()) {
708 relative_start = Smi::cast(arg1)->value();
709 } else if (arg1->IsHeapNumber()) {
710 double start = HeapNumber::cast(arg1)->value();
711 if (start < kMinInt || start > kMaxInt) {
712 AllowHeapAllocation allow_allocation;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000713 return CallJsBuiltin(isolate, "ArraySlice", args);
714 }
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000715 relative_start = std::isnan(start) ? 0 : static_cast<int>(start);
716 } else if (!arg1->IsUndefined()) {
717 AllowHeapAllocation allow_allocation;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000718 return CallJsBuiltin(isolate, "ArraySlice", args);
ager@chromium.org5c838252010-02-19 08:53:10 +0000719 }
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000720 if (n_arguments > 1) {
721 Object* arg2 = args[2];
722 if (arg2->IsSmi()) {
723 relative_end = Smi::cast(arg2)->value();
724 } else if (arg2->IsHeapNumber()) {
725 double end = HeapNumber::cast(arg2)->value();
726 if (end < kMinInt || end > kMaxInt) {
727 AllowHeapAllocation allow_allocation;
728 return CallJsBuiltin(isolate, "ArraySlice", args);
729 }
730 relative_end = std::isnan(end) ? 0 : static_cast<int>(end);
731 } else if (!arg2->IsUndefined()) {
732 AllowHeapAllocation allow_allocation;
733 return CallJsBuiltin(isolate, "ArraySlice", args);
734 }
735 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000736 }
737 }
738
739 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 6.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000740 int k = (relative_start < 0) ? Max(len + relative_start, 0)
741 : Min(relative_start, len);
ager@chromium.org5c838252010-02-19 08:53:10 +0000742
743 // ECMAScript 232, 3rd Edition, Section 15.4.4.10, step 8.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000744 int final = (relative_end < 0) ? Max(len + relative_end, 0)
745 : Min(relative_end, len);
ager@chromium.org5c838252010-02-19 08:53:10 +0000746
747 // Calculate the length of result array.
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000748 int result_len = Max(final - k, 0);
ager@chromium.org5c838252010-02-19 08:53:10 +0000749
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000750 Handle<JSObject> object = Handle<JSObject>::cast(receiver);
751 Handle<FixedArrayBase> elms(object->elements(), isolate);
752
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +0000753 ElementsKind kind = object->GetElementsKind();
754 if (IsHoleyElementsKind(kind)) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000755 DisallowHeapAllocation no_gc;
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +0000756 bool packed = true;
757 ElementsAccessor* accessor = ElementsAccessor::ForKind(kind);
758 for (int i = k; i < final; i++) {
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000759 if (!accessor->HasElement(object, object, i, elms)) {
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +0000760 packed = false;
761 break;
762 }
763 }
764 if (packed) {
765 kind = GetPackedElementsKind(kind);
766 } else if (!receiver->IsJSArray()) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000767 AllowHeapAllocation allow_allocation;
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +0000768 return CallJsBuiltin(isolate, "ArraySlice", args);
769 }
770 }
771
machenbach@chromium.orgc85dc102014-03-28 01:04:39 +0000772 Handle<JSArray> result_array =
773 isolate->factory()->NewJSArray(kind, result_len, result_len);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000774
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000775 DisallowHeapAllocation no_gc;
machenbach@chromium.orgc85dc102014-03-28 01:04:39 +0000776 if (result_len == 0) return *result_array;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000777
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000778 ElementsAccessor* accessor = object->GetElementsAccessor();
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000779 accessor->CopyElements(
780 elms, k, kind, handle(result_array->elements(), isolate), 0, result_len);
machenbach@chromium.orgc85dc102014-03-28 01:04:39 +0000781 return *result_array;
ager@chromium.org5c838252010-02-19 08:53:10 +0000782}
783
784
785BUILTIN(ArraySplice) {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000786 HandleScope scope(isolate);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000787 Heap* heap = isolate->heap();
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000788 Handle<Object> receiver = args.receiver();
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000789 MaybeHandle<FixedArrayBase> maybe_elms_obj =
machenbach@chromium.orga2218802014-03-25 07:30:47 +0000790 EnsureJSArrayWithWritableFastElements(isolate, receiver, &args, 3);
machenbach@chromium.org8f8fe812014-04-07 00:05:03 +0000791 Handle<FixedArrayBase> elms_obj;
792 if (!maybe_elms_obj.ToHandle(&elms_obj) ||
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000793 !IsJSArrayFastElementMovingAllowed(heap,
794 *Handle<JSArray>::cast(receiver))) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000795 return CallJsBuiltin(isolate, "ArraySplice", args);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000796 }
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000797 Handle<JSArray> array = Handle<JSArray>::cast(receiver);
hpayer@chromium.org7c3372b2013-02-13 17:26:04 +0000798 ASSERT(!array->map()->is_observed());
mvstanton@chromium.orge4ac3ef2012-11-12 14:53:34 +0000799
ager@chromium.org5c838252010-02-19 08:53:10 +0000800 int len = Smi::cast(array->length())->value();
801
802 int n_arguments = args.length() - 1;
803
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000804 int relative_start = 0;
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000805 if (n_arguments > 0) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000806 DisallowHeapAllocation no_gc;
807 Object* arg1 = args[1];
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000808 if (arg1->IsSmi()) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000809 relative_start = Smi::cast(arg1)->value();
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000810 } else if (arg1->IsHeapNumber()) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000811 double start = HeapNumber::cast(arg1)->value();
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000812 if (start < kMinInt || start > kMaxInt) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000813 AllowHeapAllocation allow_allocation;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000814 return CallJsBuiltin(isolate, "ArraySplice", args);
815 }
danno@chromium.orgca29dd82013-04-26 11:59:48 +0000816 relative_start = std::isnan(start) ? 0 : static_cast<int>(start);
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000817 } else if (!arg1->IsUndefined()) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000818 AllowHeapAllocation allow_allocation;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000819 return CallJsBuiltin(isolate, "ArraySplice", args);
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000820 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000821 }
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000822 int actual_start = (relative_start < 0) ? Max(len + relative_start, 0)
823 : Min(relative_start, len);
ager@chromium.org5c838252010-02-19 08:53:10 +0000824
825 // SpiderMonkey, TraceMonkey and JSC treat the case where no delete count is
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000826 // given as a request to delete all the elements from the start.
827 // And it differs from the case of undefined delete count.
ager@chromium.org5c838252010-02-19 08:53:10 +0000828 // This does not follow ECMA-262, but we do the same for
829 // compatibility.
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000830 int actual_delete_count;
831 if (n_arguments == 1) {
832 ASSERT(len - actual_start >= 0);
833 actual_delete_count = len - actual_start;
834 } else {
835 int value = 0; // ToInteger(undefined) == 0
836 if (n_arguments > 1) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000837 DisallowHeapAllocation no_gc;
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000838 Object* arg2 = args[2];
839 if (arg2->IsSmi()) {
840 value = Smi::cast(arg2)->value();
841 } else {
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000842 AllowHeapAllocation allow_allocation;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000843 return CallJsBuiltin(isolate, "ArraySplice", args);
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000844 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000845 }
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000846 actual_delete_count = Min(Max(value, 0), len - actual_start);
ager@chromium.org5c838252010-02-19 08:53:10 +0000847 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000848
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000849 ElementsKind elements_kind = array->GetElementsKind();
850
851 int item_count = (n_arguments > 1) ? (n_arguments - 2) : 0;
852 int new_length = len - actual_delete_count + item_count;
853
854 // For double mode we do not support changing the length.
855 if (new_length > len && IsFastDoubleElementsKind(elements_kind)) {
856 return CallJsBuiltin(isolate, "ArraySplice", args);
857 }
858
859 if (new_length == 0) {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000860 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000861 elms_obj, elements_kind, actual_delete_count);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000862 array->set_elements(heap->empty_fixed_array());
863 array->set_length(Smi::FromInt(0));
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000864 return *result;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000865 }
866
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000867 Handle<JSArray> result_array =
868 isolate->factory()->NewJSArray(elements_kind,
869 actual_delete_count,
870 actual_delete_count);
ager@chromium.org5c838252010-02-19 08:53:10 +0000871
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000872 if (actual_delete_count > 0) {
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000873 DisallowHeapAllocation no_gc;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000874 ElementsAccessor* accessor = array->GetElementsAccessor();
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000875 accessor->CopyElements(
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000876 elms_obj, actual_start, elements_kind,
877 handle(result_array->elements(), isolate), 0, actual_delete_count);
ager@chromium.org5c838252010-02-19 08:53:10 +0000878 }
879
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000880 bool elms_changed = false;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000881 if (item_count < actual_delete_count) {
ager@chromium.org5c838252010-02-19 08:53:10 +0000882 // Shrink the array.
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000883 const bool trim_array = !heap->lo_space()->Contains(*elms_obj) &&
lrn@chromium.org25156de2010-04-06 13:10:27 +0000884 ((actual_start + item_count) <
885 (len - actual_delete_count - actual_start));
886 if (trim_array) {
887 const int delta = actual_delete_count - item_count;
888
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000889 if (elms_obj->IsFixedDoubleArray()) {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000890 Handle<FixedDoubleArray> elms =
891 Handle<FixedDoubleArray>::cast(elms_obj);
892 MoveDoubleElements(*elms, delta, *elms, 0, actual_start);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000893 } else {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000894 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000895 DisallowHeapAllocation no_gc;
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000896 heap->MoveElements(*elms, delta, 0, actual_start);
lrn@chromium.org25156de2010-04-06 13:10:27 +0000897 }
898
machenbach@chromium.orgb5ed9302014-03-25 13:44:35 +0000899 if (heap->CanMoveObjectStart(*elms_obj)) {
900 // On the fast path we move the start of the object in memory.
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000901 elms_obj = handle(LeftTrimFixedArray(heap, *elms_obj, delta), isolate);
machenbach@chromium.orgb5ed9302014-03-25 13:44:35 +0000902 } else {
903 // This is the slow path. We are going to move the elements to the left
904 // by copying them. For trimmed values we store the hole.
905 if (elms_obj->IsFixedDoubleArray()) {
906 Handle<FixedDoubleArray> elms =
907 Handle<FixedDoubleArray>::cast(elms_obj);
908 MoveDoubleElements(*elms, 0, *elms, delta, len - delta);
machenbach@chromium.org2f599e52014-03-31 14:24:38 +0000909 elms->FillWithHoles(len - delta, len);
machenbach@chromium.orgb5ed9302014-03-25 13:44:35 +0000910 } else {
911 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
912 DisallowHeapAllocation no_gc;
913 heap->MoveElements(*elms, 0, delta, len - delta);
machenbach@chromium.org2f599e52014-03-31 14:24:38 +0000914 elms->FillWithHoles(len - delta, len);
machenbach@chromium.orgb5ed9302014-03-25 13:44:35 +0000915 }
916 }
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000917 elms_changed = true;
lrn@chromium.org25156de2010-04-06 13:10:27 +0000918 } else {
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000919 if (elms_obj->IsFixedDoubleArray()) {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000920 Handle<FixedDoubleArray> elms =
921 Handle<FixedDoubleArray>::cast(elms_obj);
922 MoveDoubleElements(*elms, actual_start + item_count,
923 *elms, actual_start + actual_delete_count,
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000924 (len - actual_delete_count - actual_start));
machenbach@chromium.org2f599e52014-03-31 14:24:38 +0000925 elms->FillWithHoles(new_length, len);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000926 } else {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000927 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000928 DisallowHeapAllocation no_gc;
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000929 heap->MoveElements(*elms, actual_start + item_count,
jkummerow@chromium.org59297c72013-01-09 16:32:23 +0000930 actual_start + actual_delete_count,
931 (len - actual_delete_count - actual_start));
machenbach@chromium.org2f599e52014-03-31 14:24:38 +0000932 elms->FillWithHoles(new_length, len);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000933 }
lrn@chromium.org25156de2010-04-06 13:10:27 +0000934 }
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000935 } else if (item_count > actual_delete_count) {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000936 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
ager@chromium.org5c838252010-02-19 08:53:10 +0000937 // Currently fixed arrays cannot grow too big, so
938 // we should never hit this case.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000939 ASSERT((item_count - actual_delete_count) <= (Smi::kMaxValue - len));
ager@chromium.org5c838252010-02-19 08:53:10 +0000940
941 // Check if array need to grow.
942 if (new_length > elms->length()) {
943 // New backing storage is needed.
944 int capacity = new_length + (new_length >> 1) + 16;
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000945 Handle<FixedArray> new_elms =
946 isolate->factory()->NewUninitializedFixedArray(capacity);
ager@chromium.org5c838252010-02-19 08:53:10 +0000947
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000948 DisallowHeapAllocation no_gc;
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000949
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000950 ElementsKind kind = array->GetElementsKind();
951 ElementsAccessor* accessor = array->GetElementsAccessor();
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000952 if (actual_start > 0) {
953 // Copy the part before actual_start as is.
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000954 accessor->CopyElements(
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000955 elms, 0, kind, new_elms, 0, actual_start);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000956 }
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000957 accessor->CopyElements(
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000958 elms, actual_start + actual_delete_count, kind,
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000959 new_elms, actual_start + item_count,
machenbach@chromium.org255043f2014-04-04 00:04:59 +0000960 ElementsAccessor::kCopyToEndAndInitializeToHole);
ager@chromium.org5c838252010-02-19 08:53:10 +0000961
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000962 elms_obj = new_elms;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000963 elms_changed = true;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000964 } else {
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000965 DisallowHeapAllocation no_gc;
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000966 heap->MoveElements(*elms, actual_start + item_count,
jkummerow@chromium.org59297c72013-01-09 16:32:23 +0000967 actual_start + actual_delete_count,
968 (len - actual_delete_count - actual_start));
ager@chromium.org5c838252010-02-19 08:53:10 +0000969 }
970 }
971
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000972 if (IsFastDoubleElementsKind(elements_kind)) {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000973 Handle<FixedDoubleArray> elms = Handle<FixedDoubleArray>::cast(elms_obj);
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000974 for (int k = actual_start; k < actual_start + item_count; k++) {
975 Object* arg = args[3 + k - actual_start];
976 if (arg->IsSmi()) {
977 elms->set(k, Smi::cast(arg)->value());
978 } else {
979 elms->set(k, HeapNumber::cast(arg)->value());
980 }
981 }
982 } else {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000983 Handle<FixedArray> elms = Handle<FixedArray>::cast(elms_obj);
rossberg@chromium.org79e79022013-06-03 15:43:46 +0000984 DisallowHeapAllocation no_gc;
yangguo@chromium.orgfb377212012-11-16 14:43:43 +0000985 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc);
986 for (int k = actual_start; k < actual_start + item_count; k++) {
987 elms->set(k, args[3 + k - actual_start], mode);
988 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000989 }
990
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000991 if (elms_changed) {
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000992 array->set_elements(*elms_obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000993 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000994 // Set the length.
995 array->set_length(Smi::FromInt(new_length));
996
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +0000997 return *result_array;
ager@chromium.org5c838252010-02-19 08:53:10 +0000998}
999
1000
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001001BUILTIN(ArrayConcat) {
machenbach@chromium.orgc85dc102014-03-28 01:04:39 +00001002 HandleScope scope(isolate);
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001003
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001004 int n_arguments = args.length();
1005 int result_len = 0;
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001006 ElementsKind elements_kind = GetInitialFastElementsKind();
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001007 bool has_double = false;
machenbach@chromium.org255043f2014-04-04 00:04:59 +00001008 {
1009 DisallowHeapAllocation no_gc;
1010 Heap* heap = isolate->heap();
1011 Context* native_context = isolate->context()->native_context();
1012 JSObject* array_proto =
1013 JSObject::cast(native_context->array_function()->prototype());
1014 if (!ArrayPrototypeHasNoElements(heap, native_context, array_proto)) {
1015 AllowHeapAllocation allow_allocation;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001016 return CallJsBuiltin(isolate, "ArrayConcat", args);
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001017 }
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001018
machenbach@chromium.org255043f2014-04-04 00:04:59 +00001019 // Iterate through all the arguments performing checks
1020 // and calculating total length.
1021 bool is_holey = false;
1022 for (int i = 0; i < n_arguments; i++) {
1023 Object* arg = args[i];
1024 if (!arg->IsJSArray() ||
1025 !JSArray::cast(arg)->HasFastElements() ||
1026 JSArray::cast(arg)->GetPrototype() != array_proto) {
1027 AllowHeapAllocation allow_allocation;
1028 return CallJsBuiltin(isolate, "ArrayConcat", args);
1029 }
1030 int len = Smi::cast(JSArray::cast(arg)->length())->value();
1031
1032 // We shouldn't overflow when adding another len.
1033 const int kHalfOfMaxInt = 1 << (kBitsPerInt - 2);
1034 STATIC_ASSERT(FixedArray::kMaxLength < kHalfOfMaxInt);
1035 USE(kHalfOfMaxInt);
1036 result_len += len;
1037 ASSERT(result_len >= 0);
1038
1039 if (result_len > FixedDoubleArray::kMaxLength) {
1040 AllowHeapAllocation allow_allocation;
1041 return CallJsBuiltin(isolate, "ArrayConcat", args);
1042 }
1043
1044 ElementsKind arg_kind = JSArray::cast(arg)->map()->elements_kind();
1045 has_double = has_double || IsFastDoubleElementsKind(arg_kind);
1046 is_holey = is_holey || IsFastHoleyElementsKind(arg_kind);
1047 if (IsMoreGeneralElementsKindTransition(elements_kind, arg_kind)) {
1048 elements_kind = arg_kind;
1049 }
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001050 }
machenbach@chromium.org255043f2014-04-04 00:04:59 +00001051 if (is_holey) elements_kind = GetHoleyElementsKind(elements_kind);
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001052 }
1053
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001054 // If a double array is concatted into a fast elements array, the fast
1055 // elements array needs to be initialized to contain proper holes, since
1056 // boxing doubles may cause incremental marking.
1057 ArrayStorageAllocationMode mode =
1058 has_double && IsFastObjectElementsKind(elements_kind)
1059 ? INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE : DONT_INITIALIZE_ARRAY_ELEMENTS;
machenbach@chromium.orgc85dc102014-03-28 01:04:39 +00001060 Handle<JSArray> result_array =
1061 isolate->factory()->NewJSArray(elements_kind,
1062 result_len,
1063 result_len,
1064 mode);
1065 if (result_len == 0) return *result_array;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001066
yangguo@chromium.orgfb377212012-11-16 14:43:43 +00001067 int j = 0;
machenbach@chromium.org255043f2014-04-04 00:04:59 +00001068 Handle<FixedArrayBase> storage(result_array->elements(), isolate);
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +00001069 ElementsAccessor* accessor = ElementsAccessor::ForKind(elements_kind);
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001070 for (int i = 0; i < n_arguments; i++) {
machenbach@chromium.org255043f2014-04-04 00:04:59 +00001071 // TODO(ishell): It is crucial to keep |array| as a raw pointer to avoid
1072 // performance degradation. Revisit this later.
1073 JSArray* array = JSArray::cast(args[i]);
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001074 int len = Smi::cast(array->length())->value();
yangguo@chromium.org4cd70b42013-01-04 08:57:54 +00001075 ElementsKind from_kind = array->GetElementsKind();
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001076 if (len > 0) {
machenbach@chromium.orgc85dc102014-03-28 01:04:39 +00001077 accessor->CopyElements(array, 0, from_kind, storage, j, len);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +00001078 j += len;
1079 }
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001080 }
yangguo@chromium.orgfb377212012-11-16 14:43:43 +00001081
1082 ASSERT(j == result_len);
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001083
machenbach@chromium.orgc85dc102014-03-28 01:04:39 +00001084 return *result_array;
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001085}
1086
1087
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001088// -----------------------------------------------------------------------------
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001089// Strict mode poison pills
1090
1091
danno@chromium.org40cb8782011-05-25 07:58:50 +00001092BUILTIN(StrictModePoisonPill) {
yangguo@chromium.orgc03a1922013-02-19 13:55:47 +00001093 HandleScope scope(isolate);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001094 return isolate->Throw(*isolate->factory()->NewTypeError(
danno@chromium.org40cb8782011-05-25 07:58:50 +00001095 "strict_poison_pill", HandleVector<Object>(NULL, 0)));
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001096}
1097
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +00001098
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001099// -----------------------------------------------------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001100//
1101
1102
mmassi@chromium.org49a44672012-12-04 13:52:03 +00001103// Searches the hidden prototype chain of the given object for the first
1104// object that is an instance of the given type. If no such object can
1105// be found then Heap::null_value() is returned.
1106static inline Object* FindHidden(Heap* heap,
1107 Object* object,
1108 FunctionTemplateInfo* type) {
machenbach@chromium.org9af454f2013-11-20 09:25:57 +00001109 if (type->IsTemplateFor(object)) return object;
hpayer@chromium.org8432c912013-02-28 15:55:26 +00001110 Object* proto = object->GetPrototype(heap->isolate());
mmassi@chromium.org49a44672012-12-04 13:52:03 +00001111 if (proto->IsJSObject() &&
1112 JSObject::cast(proto)->map()->is_hidden_prototype()) {
1113 return FindHidden(heap, proto, type);
1114 }
1115 return heap->null_value();
1116}
1117
1118
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001119// Returns the holder JSObject if the function can legally be called
1120// with this receiver. Returns Heap::null_value() if the call is
1121// illegal. Any arguments that don't fit the expected type is
mmassi@chromium.org49a44672012-12-04 13:52:03 +00001122// overwritten with undefined. Note that holder and the arguments are
1123// implicitly rewritten with the first object in the hidden prototype
1124// chain that actually has the expected type.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001125static inline Object* TypeCheck(Heap* heap,
1126 int argc,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001127 Object** argv,
1128 FunctionTemplateInfo* info) {
1129 Object* recv = argv[0];
lrn@chromium.org1c092762011-05-09 09:42:16 +00001130 // API calls are only supported with JSObject receivers.
1131 if (!recv->IsJSObject()) return heap->null_value();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001132 Object* sig_obj = info->signature();
1133 if (sig_obj->IsUndefined()) return recv;
1134 SignatureInfo* sig = SignatureInfo::cast(sig_obj);
1135 // If necessary, check the receiver
1136 Object* recv_type = sig->receiver();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001137 Object* holder = recv;
1138 if (!recv_type->IsUndefined()) {
mmassi@chromium.org49a44672012-12-04 13:52:03 +00001139 holder = FindHidden(heap, holder, FunctionTemplateInfo::cast(recv_type));
1140 if (holder == heap->null_value()) return heap->null_value();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001141 }
1142 Object* args_obj = sig->args();
1143 // If there is no argument signature we're done
1144 if (args_obj->IsUndefined()) return holder;
1145 FixedArray* args = FixedArray::cast(args_obj);
1146 int length = args->length();
mads.s.ager31e71382008-08-13 09:32:07 +00001147 if (argc <= length) length = argc - 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001148 for (int i = 0; i < length; i++) {
1149 Object* argtype = args->get(i);
1150 if (argtype->IsUndefined()) continue;
1151 Object** arg = &argv[-1 - i];
1152 Object* current = *arg;
mmassi@chromium.org49a44672012-12-04 13:52:03 +00001153 current = FindHidden(heap, current, FunctionTemplateInfo::cast(argtype));
1154 if (current == heap->null_value()) current = heap->undefined_value();
1155 *arg = current;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001156 }
1157 return holder;
1158}
1159
1160
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001161template <bool is_construct>
lrn@chromium.org303ada72010-10-27 09:33:13 +00001162MUST_USE_RESULT static MaybeObject* HandleApiCallHelper(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001163 BuiltinArguments<NEEDS_CALLED_FUNCTION> args, Isolate* isolate) {
1164 ASSERT(is_construct == CalledAsConstructor(isolate));
1165 Heap* heap = isolate->heap();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001166
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001167 HandleScope scope(isolate);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001168 Handle<JSFunction> function = args.called_function();
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001169 ASSERT(function->shared()->IsApiFunction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001170
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001171 FunctionTemplateInfo* fun_data = function->shared()->get_api_func_data();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001172 if (is_construct) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001173 Handle<FunctionTemplateInfo> desc(fun_data, isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001174 bool pending_exception = false;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001175 isolate->factory()->ConfigureInstance(
1176 desc, Handle<JSObject>::cast(args.receiver()), &pending_exception);
1177 ASSERT(isolate->has_pending_exception() == pending_exception);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001178 if (pending_exception) return Failure::Exception();
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001179 fun_data = *desc;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001180 }
1181
machenbach@chromium.orge31286d2014-01-15 10:29:52 +00001182 SharedFunctionInfo* shared = function->shared();
dslomov@chromium.org486536d2014-03-12 13:09:18 +00001183 if (shared->strict_mode() == SLOPPY && !shared->native()) {
machenbach@chromium.orge31286d2014-01-15 10:29:52 +00001184 Object* recv = args[0];
1185 ASSERT(!recv->IsNull());
1186 if (recv->IsUndefined()) {
1187 args[0] = function->context()->global_object()->global_receiver();
1188 }
1189 }
1190
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001191 Object* raw_holder = TypeCheck(heap, args.length(), &args[0], fun_data);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001192
1193 if (raw_holder->IsNull()) {
1194 // This function cannot be called with the given receiver. Abort!
1195 Handle<Object> obj =
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001196 isolate->factory()->NewTypeError(
1197 "illegal_invocation", HandleVector(&function, 1));
1198 return isolate->Throw(*obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001199 }
1200
1201 Object* raw_call_data = fun_data->call_code();
1202 if (!raw_call_data->IsUndefined()) {
1203 CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data);
1204 Object* callback_obj = call_data->callback();
verwaest@chromium.org662436e2013-08-28 08:41:27 +00001205 v8::FunctionCallback callback =
1206 v8::ToCData<v8::FunctionCallback>(callback_obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001207 Object* data_obj = call_data->data();
1208 Object* result;
1209
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001210 LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver())));
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00001211 ASSERT(raw_holder->IsJSObject());
1212
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001213 FunctionCallbackArguments custom(isolate,
1214 data_obj,
1215 *function,
1216 raw_holder,
1217 &args[0] - 1,
1218 args.length() - 1,
1219 is_construct);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001220
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +00001221 v8::Handle<v8::Value> value = custom.Call(callback);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001222 if (value.IsEmpty()) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001223 result = heap->undefined_value();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001224 } else {
1225 result = *reinterpret_cast<Object**>(*value);
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00001226 result->VerifyApiCallResultType();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001227 }
1228
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001229 RETURN_IF_SCHEDULED_EXCEPTION(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001230 if (!is_construct || result->IsJSObject()) return result;
1231 }
1232
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001233 return *args.receiver();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001234}
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001235
1236
1237BUILTIN(HandleApiCall) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001238 return HandleApiCallHelper<false>(args, isolate);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001239}
1240
1241
1242BUILTIN(HandleApiCallConstruct) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001243 return HandleApiCallHelper<true>(args, isolate);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001244}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001245
1246
sgjesse@chromium.org05521fc2009-05-21 07:37:44 +00001247// Helper function to handle calls to non-function objects created through the
1248// API. The object can be called as either a constructor (using new) or just as
1249// a function (without new).
lrn@chromium.org303ada72010-10-27 09:33:13 +00001250MUST_USE_RESULT static MaybeObject* HandleApiCallAsFunctionOrConstructor(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001251 Isolate* isolate,
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001252 bool is_construct_call,
1253 BuiltinArguments<NO_EXTRA_ARGUMENTS> args) {
sgjesse@chromium.org05521fc2009-05-21 07:37:44 +00001254 // Non-functions are never called as constructors. Even if this is an object
1255 // called as a constructor the delegate call is not a construct call.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001256 ASSERT(!CalledAsConstructor(isolate));
1257 Heap* heap = isolate->heap();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001258
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001259 Handle<Object> receiver = args.receiver();
sgjesse@chromium.org05521fc2009-05-21 07:37:44 +00001260
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001261 // Get the object called.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001262 JSObject* obj = JSObject::cast(*receiver);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001263
1264 // Get the invocation callback from the function descriptor that was
1265 // used to create the called object.
1266 ASSERT(obj->map()->has_instance_call_handler());
1267 JSFunction* constructor = JSFunction::cast(obj->map()->constructor());
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001268 ASSERT(constructor->shared()->IsApiFunction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001269 Object* handler =
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00001270 constructor->shared()->get_api_func_data()->instance_call_handler();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001271 ASSERT(!handler->IsUndefined());
1272 CallHandlerInfo* call_data = CallHandlerInfo::cast(handler);
1273 Object* callback_obj = call_data->callback();
verwaest@chromium.org662436e2013-08-28 08:41:27 +00001274 v8::FunctionCallback callback =
1275 v8::ToCData<v8::FunctionCallback>(callback_obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001276
1277 // Get the data for the call and perform the callback.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001278 Object* result;
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00001279 {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001280 HandleScope scope(isolate);
1281 LOG(isolate, ApiObjectAccess("call non-function", obj));
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00001282
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001283 FunctionCallbackArguments custom(isolate,
1284 call_data->data(),
1285 constructor,
1286 obj,
1287 &args[0] - 1,
1288 args.length() - 1,
1289 is_construct_call);
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +00001290 v8::Handle<v8::Value> value = custom.Call(callback);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001291 if (value.IsEmpty()) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001292 result = heap->undefined_value();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001293 } else {
1294 result = *reinterpret_cast<Object**>(*value);
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00001295 result->VerifyApiCallResultType();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001296 }
1297 }
1298 // Check for exceptions and return result.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001299 RETURN_IF_SCHEDULED_EXCEPTION(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001300 return result;
1301}
sgjesse@chromium.org05521fc2009-05-21 07:37:44 +00001302
1303
1304// Handle calls to non-function objects created through the API. This delegate
1305// function is used when the call is a normal function call.
1306BUILTIN(HandleApiCallAsFunction) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001307 return HandleApiCallAsFunctionOrConstructor(isolate, false, args);
sgjesse@chromium.org05521fc2009-05-21 07:37:44 +00001308}
sgjesse@chromium.org05521fc2009-05-21 07:37:44 +00001309
1310
1311// Handle calls to non-function objects created through the API. This delegate
1312// function is used when the call is a construct call.
1313BUILTIN(HandleApiCallAsConstructor) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001314 return HandleApiCallAsFunctionOrConstructor(isolate, true, args);
sgjesse@chromium.org05521fc2009-05-21 07:37:44 +00001315}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001316
1317
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001318static void Generate_LoadIC_Miss(MacroAssembler* masm) {
1319 LoadIC::GenerateMiss(masm);
1320}
1321
1322
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001323static void Generate_LoadIC_Normal(MacroAssembler* masm) {
1324 LoadIC::GenerateNormal(masm);
1325}
1326
1327
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00001328static void Generate_LoadIC_Getter_ForDeopt(MacroAssembler* masm) {
machenbach@chromium.orgca2f2042014-03-10 10:03:12 +00001329 LoadStubCompiler::GenerateLoadViaGetterForDeopt(masm);
mstarzinger@chromium.orgde886792012-09-11 13:22:37 +00001330}
1331
1332
verwaest@chromium.orgd4be0f02013-06-05 13:39:03 +00001333static void Generate_LoadIC_Slow(MacroAssembler* masm) {
1334 LoadIC::GenerateRuntimeGetProperty(masm);
1335}
1336
1337
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001338static void Generate_KeyedLoadIC_Initialize(MacroAssembler* masm) {
1339 KeyedLoadIC::GenerateInitialize(masm);
1340}
1341
1342
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001343static void Generate_KeyedLoadIC_Slow(MacroAssembler* masm) {
1344 KeyedLoadIC::GenerateRuntimeGetProperty(masm);
1345}
1346
1347
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001348static void Generate_KeyedLoadIC_Miss(MacroAssembler* masm) {
machenbach@chromium.orgaf9cfcb2013-11-19 11:05:18 +00001349 KeyedLoadIC::GenerateMiss(masm);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001350}
1351
1352
1353static void Generate_KeyedLoadIC_Generic(MacroAssembler* masm) {
1354 KeyedLoadIC::GenerateGeneric(masm);
1355}
1356
1357
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00001358static void Generate_KeyedLoadIC_String(MacroAssembler* masm) {
1359 KeyedLoadIC::GenerateString(masm);
1360}
1361
1362
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001363static void Generate_KeyedLoadIC_PreMonomorphic(MacroAssembler* masm) {
1364 KeyedLoadIC::GeneratePreMonomorphic(masm);
1365}
1366
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +00001367
ager@chromium.org5c838252010-02-19 08:53:10 +00001368static void Generate_KeyedLoadIC_IndexedInterceptor(MacroAssembler* masm) {
1369 KeyedLoadIC::GenerateIndexedInterceptor(masm);
1370}
1371
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +00001372
dslomov@chromium.org486536d2014-03-12 13:09:18 +00001373static void Generate_KeyedLoadIC_SloppyArguments(MacroAssembler* masm) {
1374 KeyedLoadIC::GenerateSloppyArguments(masm);
whesse@chromium.org7b260152011-06-20 15:33:18 +00001375}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001376
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +00001377
ulan@chromium.org57ff8812013-05-10 08:16:55 +00001378static void Generate_StoreIC_Slow(MacroAssembler* masm) {
1379 StoreIC::GenerateSlow(masm);
1380}
1381
1382
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001383static void Generate_StoreIC_Miss(MacroAssembler* masm) {
1384 StoreIC::GenerateMiss(masm);
1385}
1386
1387
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00001388static void Generate_StoreIC_Normal(MacroAssembler* masm) {
1389 StoreIC::GenerateNormal(masm);
1390}
1391
1392
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00001393static void Generate_StoreIC_Setter_ForDeopt(MacroAssembler* masm) {
machenbach@chromium.orgca2f2042014-03-10 10:03:12 +00001394 StoreStubCompiler::GenerateStoreViaSetterForDeopt(masm);
yangguo@chromium.org46839fb2012-08-28 09:06:19 +00001395}
1396
1397
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001398static void Generate_KeyedStoreIC_Generic(MacroAssembler* masm) {
dslomov@chromium.org486536d2014-03-12 13:09:18 +00001399 KeyedStoreIC::GenerateGeneric(masm, SLOPPY);
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001400}
1401
1402
1403static void Generate_KeyedStoreIC_Generic_Strict(MacroAssembler* masm) {
dslomov@chromium.org486536d2014-03-12 13:09:18 +00001404 KeyedStoreIC::GenerateGeneric(masm, STRICT);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001405}
1406
1407
1408static void Generate_KeyedStoreIC_Miss(MacroAssembler* masm) {
machenbach@chromium.orgaf9cfcb2013-11-19 11:05:18 +00001409 KeyedStoreIC::GenerateMiss(masm);
ager@chromium.orgea91cc52011-05-23 06:06:11 +00001410}
1411
1412
1413static void Generate_KeyedStoreIC_Slow(MacroAssembler* masm) {
1414 KeyedStoreIC::GenerateSlow(masm);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001415}
1416
1417
1418static void Generate_KeyedStoreIC_Initialize(MacroAssembler* masm) {
1419 KeyedStoreIC::GenerateInitialize(masm);
1420}
1421
1422
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001423static void Generate_KeyedStoreIC_Initialize_Strict(MacroAssembler* masm) {
1424 KeyedStoreIC::GenerateInitialize(masm);
1425}
1426
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +00001427
jkummerow@chromium.org3d00d0a2013-09-04 13:57:32 +00001428static void Generate_KeyedStoreIC_PreMonomorphic(MacroAssembler* masm) {
1429 KeyedStoreIC::GeneratePreMonomorphic(masm);
1430}
1431
1432
1433static void Generate_KeyedStoreIC_PreMonomorphic_Strict(MacroAssembler* masm) {
1434 KeyedStoreIC::GeneratePreMonomorphic(masm);
1435}
1436
1437
dslomov@chromium.org486536d2014-03-12 13:09:18 +00001438static void Generate_KeyedStoreIC_SloppyArguments(MacroAssembler* masm) {
1439 KeyedStoreIC::GenerateSloppyArguments(masm);
whesse@chromium.org7b260152011-06-20 15:33:18 +00001440}
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001441
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +00001442
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001443#ifdef ENABLE_DEBUGGER_SUPPORT
ager@chromium.org8bb60582008-12-11 12:02:20 +00001444static void Generate_LoadIC_DebugBreak(MacroAssembler* masm) {
1445 Debug::GenerateLoadICDebugBreak(masm);
1446}
1447
1448
1449static void Generate_StoreIC_DebugBreak(MacroAssembler* masm) {
1450 Debug::GenerateStoreICDebugBreak(masm);
1451}
1452
1453
1454static void Generate_KeyedLoadIC_DebugBreak(MacroAssembler* masm) {
1455 Debug::GenerateKeyedLoadICDebugBreak(masm);
1456}
1457
1458
1459static void Generate_KeyedStoreIC_DebugBreak(MacroAssembler* masm) {
1460 Debug::GenerateKeyedStoreICDebugBreak(masm);
1461}
1462
1463
danno@chromium.orgf005df62013-04-30 16:36:45 +00001464static void Generate_CompareNilIC_DebugBreak(MacroAssembler* masm) {
1465 Debug::GenerateCompareNilICDebugBreak(masm);
1466}
1467
1468
ager@chromium.org8bb60582008-12-11 12:02:20 +00001469static void Generate_Return_DebugBreak(MacroAssembler* masm) {
1470 Debug::GenerateReturnDebugBreak(masm);
1471}
1472
1473
danno@chromium.orgc612e022011-11-10 11:38:15 +00001474static void Generate_CallFunctionStub_DebugBreak(MacroAssembler* masm) {
1475 Debug::GenerateCallFunctionStubDebugBreak(masm);
ager@chromium.org8bb60582008-12-11 12:02:20 +00001476}
ager@chromium.org357bf652010-04-12 11:30:10 +00001477
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001478
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001479static void Generate_CallFunctionStub_Recording_DebugBreak(
1480 MacroAssembler* masm) {
1481 Debug::GenerateCallFunctionStubRecordDebugBreak(masm);
1482}
1483
1484
1485static void Generate_CallConstructStub_DebugBreak(MacroAssembler* masm) {
1486 Debug::GenerateCallConstructStubDebugBreak(masm);
1487}
1488
1489
1490static void Generate_CallConstructStub_Recording_DebugBreak(
1491 MacroAssembler* masm) {
1492 Debug::GenerateCallConstructStubRecordDebugBreak(masm);
1493}
1494
1495
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001496static void Generate_Slot_DebugBreak(MacroAssembler* masm) {
1497 Debug::GenerateSlotDebugBreak(masm);
1498}
1499
1500
ager@chromium.org357bf652010-04-12 11:30:10 +00001501static void Generate_PlainReturn_LiveEdit(MacroAssembler* masm) {
1502 Debug::GeneratePlainReturnLiveEdit(masm);
1503}
1504
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001505
ager@chromium.org357bf652010-04-12 11:30:10 +00001506static void Generate_FrameDropper_LiveEdit(MacroAssembler* masm) {
1507 Debug::GenerateFrameDropperLiveEdit(masm);
1508}
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001509#endif
ager@chromium.org8bb60582008-12-11 12:02:20 +00001510
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001511
1512Builtins::Builtins() : initialized_(false) {
1513 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count);
1514 memset(names_, 0, sizeof(names_[0]) * builtin_count);
1515}
1516
1517
1518Builtins::~Builtins() {
1519}
1520
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001521
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001522#define DEF_ENUM_C(name, ignore) FUNCTION_ADDR(Builtin_##name),
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001523Address const Builtins::c_functions_[cfunction_count] = {
1524 BUILTIN_LIST_C(DEF_ENUM_C)
1525};
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001526#undef DEF_ENUM_C
1527
1528#define DEF_JS_NAME(name, ignore) #name,
1529#define DEF_JS_ARGC(ignore, argc) argc,
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001530const char* const Builtins::javascript_names_[id_count] = {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001531 BUILTINS_LIST_JS(DEF_JS_NAME)
1532};
1533
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001534int const Builtins::javascript_argc_[id_count] = {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001535 BUILTINS_LIST_JS(DEF_JS_ARGC)
1536};
1537#undef DEF_JS_NAME
1538#undef DEF_JS_ARGC
1539
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001540struct BuiltinDesc {
1541 byte* generator;
1542 byte* c_code;
1543 const char* s_name; // name is only used for generating log information.
1544 int name;
1545 Code::Flags flags;
1546 BuiltinExtraArguments extra_args;
1547};
1548
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00001549#define BUILTIN_FUNCTION_TABLE_INIT { V8_ONCE_INIT, {} }
1550
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001551class BuiltinFunctionTable {
1552 public:
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00001553 BuiltinDesc* functions() {
1554 CallOnce(&once_, &Builtins::InitBuiltinFunctionTable);
1555 return functions_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001556 }
1557
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00001558 OnceType once_;
1559 BuiltinDesc functions_[Builtins::builtin_count + 1];
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001560
1561 friend class Builtins;
1562};
1563
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00001564static BuiltinFunctionTable builtin_function_table =
1565 BUILTIN_FUNCTION_TABLE_INIT;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001566
1567// Define array of pointers to generators and C builtin functions.
1568// We do this in a sort of roundabout way so that we can do the initialization
1569// within the lexical scope of Builtins:: and within a context where
1570// Code::Flags names a non-abstract type.
1571void Builtins::InitBuiltinFunctionTable() {
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00001572 BuiltinDesc* functions = builtin_function_table.functions_;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001573 functions[builtin_count].generator = NULL;
1574 functions[builtin_count].c_code = NULL;
1575 functions[builtin_count].s_name = NULL;
1576 functions[builtin_count].name = builtin_count;
1577 functions[builtin_count].flags = static_cast<Code::Flags>(0);
1578 functions[builtin_count].extra_args = NO_EXTRA_ARGUMENTS;
1579
1580#define DEF_FUNCTION_PTR_C(aname, aextra_args) \
1581 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \
1582 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \
1583 functions->s_name = #aname; \
1584 functions->name = c_##aname; \
1585 functions->flags = Code::ComputeFlags(Code::BUILTIN); \
1586 functions->extra_args = aextra_args; \
1587 ++functions;
1588
1589#define DEF_FUNCTION_PTR_A(aname, kind, state, extra) \
1590 functions->generator = FUNCTION_ADDR(Generate_##aname); \
1591 functions->c_code = NULL; \
1592 functions->s_name = #aname; \
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001593 functions->name = k##aname; \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001594 functions->flags = Code::ComputeFlags(Code::kind, \
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001595 state, \
1596 extra); \
1597 functions->extra_args = NO_EXTRA_ARGUMENTS; \
1598 ++functions;
1599
machenbach@chromium.orgc86e8c22013-11-27 15:11:04 +00001600#define DEF_FUNCTION_PTR_H(aname, kind) \
jkummerow@chromium.org32aa03c2013-10-01 08:21:50 +00001601 functions->generator = FUNCTION_ADDR(Generate_##aname); \
1602 functions->c_code = NULL; \
1603 functions->s_name = #aname; \
1604 functions->name = k##aname; \
titzer@chromium.orgf5a24542014-03-04 09:06:17 +00001605 functions->flags = Code::ComputeHandlerFlags(Code::kind); \
jkummerow@chromium.org32aa03c2013-10-01 08:21:50 +00001606 functions->extra_args = NO_EXTRA_ARGUMENTS; \
1607 ++functions;
1608
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001609 BUILTIN_LIST_C(DEF_FUNCTION_PTR_C)
1610 BUILTIN_LIST_A(DEF_FUNCTION_PTR_A)
jkummerow@chromium.org32aa03c2013-10-01 08:21:50 +00001611 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H)
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001612 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A)
1613
1614#undef DEF_FUNCTION_PTR_C
1615#undef DEF_FUNCTION_PTR_A
1616}
1617
mstarzinger@chromium.orge0e1b0d2013-07-08 08:38:06 +00001618
mstarzinger@chromium.orge9000182013-09-03 11:25:39 +00001619void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001620 ASSERT(!initialized_);
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001621 Heap* heap = isolate->heap();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001622
1623 // Create a scope for the handles in the builtins.
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001624 HandleScope scope(isolate);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001625
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00001626 const BuiltinDesc* functions = builtin_function_table.functions();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001627
1628 // For now we generate builtin adaptor code into a stack-allocated
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001629 // buffer, before copying it into individual code objects. Be careful
1630 // with alignment, some platforms don't like unaligned code.
titzer@chromium.orgf5a24542014-03-04 09:06:17 +00001631 // TODO(jbramley): I had to increase the size of this buffer from 8KB because
machenbach@chromium.orgfa0c3c62014-03-24 08:11:09 +00001632 // we can generate a lot of debug code on ARM64.
titzer@chromium.orgf5a24542014-03-04 09:06:17 +00001633 union { int force_alignment; byte buffer[16*KB]; } u;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001634
1635 // Traverse the list of builtins and generate an adaptor in a
1636 // separate code object for each one.
1637 for (int i = 0; i < builtin_count; i++) {
1638 if (create_heap_objects) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001639 MacroAssembler masm(isolate, u.buffer, sizeof u.buffer);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001640 // Generate the code/adaptor.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001641 typedef void (*Generator)(MacroAssembler*, int, BuiltinExtraArguments);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001642 Generator g = FUNCTION_CAST<Generator>(functions[i].generator);
1643 // We pass all arguments to the generator, but it may not use all of
1644 // them. This works because the first arguments are on top of the
1645 // stack.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001646 ASSERT(!masm.has_frame());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001647 g(&masm, functions[i].name, functions[i].extra_args);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001648 // Move the code into the object heap.
1649 CodeDesc desc;
1650 masm.GetCode(&desc);
1651 Code::Flags flags = functions[i].flags;
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00001652 Object* code = NULL;
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +00001653 {
1654 // During startup it's OK to always allocate and defer GC to later.
1655 // This simplifies things because we don't need to retry.
machenbach@chromium.org56971442014-03-19 13:13:40 +00001656 AlwaysAllocateScope __scope__(isolate);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001657 { MaybeObject* maybe_code =
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001658 heap->CreateCode(desc, flags, masm.CodeObject());
lrn@chromium.org303ada72010-10-27 09:33:13 +00001659 if (!maybe_code->ToObject(&code)) {
1660 v8::internal::V8::FatalProcessOutOfMemory("CreateCode");
1661 }
ager@chromium.org7c537e22008-10-16 08:43:32 +00001662 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001663 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001664 // Log the event and add the code to the builtins array.
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +00001665 PROFILE(isolate,
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001666 CodeCreateEvent(Logger::BUILTIN_TAG,
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00001667 Code::cast(code),
1668 functions[i].s_name));
1669 GDBJIT(AddCode(GDBJITInterface::BUILTIN,
1670 functions[i].s_name,
1671 Code::cast(code)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001672 builtins_[i] = code;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001673#ifdef ENABLE_DISASSEMBLER
mads.s.ager31e71382008-08-13 09:32:07 +00001674 if (FLAG_print_builtin_code) {
machenbach@chromium.orge8412be2013-11-08 10:23:52 +00001675 CodeTracer::Scope trace_scope(isolate->GetCodeTracer());
1676 PrintF(trace_scope.file(), "Builtin: %s\n", functions[i].s_name);
1677 Code::cast(code)->Disassemble(functions[i].s_name, trace_scope.file());
1678 PrintF(trace_scope.file(), "\n");
mads.s.ager31e71382008-08-13 09:32:07 +00001679 }
1680#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001681 } else {
1682 // Deserializing. The values will be filled in during IterateBuiltins.
1683 builtins_[i] = NULL;
1684 }
1685 names_[i] = functions[i].s_name;
1686 }
1687
1688 // Mark as initialized.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001689 initialized_ = true;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001690}
1691
1692
1693void Builtins::TearDown() {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001694 initialized_ = false;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001695}
1696
1697
1698void Builtins::IterateBuiltins(ObjectVisitor* v) {
1699 v->VisitPointers(&builtins_[0], &builtins_[0] + builtin_count);
1700}
1701
1702
1703const char* Builtins::Lookup(byte* pc) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001704 // may be called during initialization (disassembler!)
1705 if (initialized_) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001706 for (int i = 0; i < builtin_count; i++) {
1707 Code* entry = Code::cast(builtins_[i]);
1708 if (entry->contains(pc)) {
1709 return names_[i];
1710 }
1711 }
1712 }
1713 return NULL;
1714}
1715
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001716
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001717void Builtins::Generate_InterruptCheck(MacroAssembler* masm) {
machenbach@chromium.org895f00d2014-03-27 01:04:43 +00001718 masm->TailCallRuntime(Runtime::kHiddenInterrupt, 0, 1);
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001719}
1720
1721
1722void Builtins::Generate_StackCheck(MacroAssembler* masm) {
machenbach@chromium.org895f00d2014-03-27 01:04:43 +00001723 masm->TailCallRuntime(Runtime::kHiddenStackGuard, 0, 1);
jkummerow@chromium.orgdc94e192013-08-30 11:35:42 +00001724}
1725
1726
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001727#define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \
1728Handle<Code> Builtins::name() { \
1729 Code** code_address = \
1730 reinterpret_cast<Code**>(builtin_address(k##name)); \
1731 return Handle<Code>(code_address); \
1732}
1733#define DEFINE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \
1734Handle<Code> Builtins::name() { \
1735 Code** code_address = \
1736 reinterpret_cast<Code**>(builtin_address(k##name)); \
1737 return Handle<Code>(code_address); \
1738}
machenbach@chromium.orgc86e8c22013-11-27 15:11:04 +00001739#define DEFINE_BUILTIN_ACCESSOR_H(name, kind) \
jkummerow@chromium.org32aa03c2013-10-01 08:21:50 +00001740Handle<Code> Builtins::name() { \
1741 Code** code_address = \
1742 reinterpret_cast<Code**>(builtin_address(k##name)); \
1743 return Handle<Code>(code_address); \
1744}
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001745BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1746BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
jkummerow@chromium.org32aa03c2013-10-01 08:21:50 +00001747BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
fschneider@chromium.org7979bbb2011-03-28 10:47:03 +00001748BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1749#undef DEFINE_BUILTIN_ACCESSOR_C
1750#undef DEFINE_BUILTIN_ACCESSOR_A
1751
1752
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001753} } // namespace v8::internal