| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // Optimize the case where there are no parameters passed. | 240 // Optimize the case where there are no parameters passed. |
| 241 if (args.length() == 1) { | 241 if (args.length() == 1) { |
| 242 return array->Initialize(JSArray::kPreallocatedArrayElements); | 242 return array->Initialize(JSArray::kPreallocatedArrayElements); |
| 243 } | 243 } |
| 244 | 244 |
| 245 // Take the arguments as elements. | 245 // Take the arguments as elements. |
| 246 int number_of_elements = args.length() - 1; | 246 int number_of_elements = args.length() - 1; |
| 247 Smi* len = Smi::FromInt(number_of_elements); | 247 Smi* len = Smi::FromInt(number_of_elements); |
| 248 Object* obj = Heap::AllocateFixedArrayWithHoles(len->value()); | 248 Object* obj = Heap::AllocateFixedArrayWithHoles(len->value()); |
| 249 if (obj->IsFailure()) return obj; | 249 if (obj->IsFailure()) return obj; |
| 250 |
| 251 AssertNoAllocation no_gc; |
| 250 FixedArray* elms = FixedArray::cast(obj); | 252 FixedArray* elms = FixedArray::cast(obj); |
| 251 WriteBarrierMode mode = elms->GetWriteBarrierMode(); | 253 WriteBarrierMode mode = elms->GetWriteBarrierMode(no_gc); |
| 252 // Fill in the content | 254 // Fill in the content |
| 253 for (int index = 0; index < number_of_elements; index++) { | 255 for (int index = 0; index < number_of_elements; index++) { |
| 254 elms->set(index, args[index+1], mode); | 256 elms->set(index, args[index+1], mode); |
| 255 } | 257 } |
| 256 | 258 |
| 257 // Set length and elements on the array. | 259 // Set length and elements on the array. |
| 258 array->set_elements(FixedArray::cast(obj)); | 260 array->set_elements(FixedArray::cast(obj)); |
| 259 array->set_length(len, SKIP_WRITE_BARRIER); | 261 array->set_length(len); |
| 260 | 262 |
| 261 return array; | 263 return array; |
| 262 } | 264 } |
| 263 | 265 |
| 264 | 266 |
| 265 BUILTIN(ArrayPush) { | 267 BUILTIN(ArrayPush) { |
| 266 JSArray* array = JSArray::cast(*args.receiver()); | 268 JSArray* array = JSArray::cast(*args.receiver()); |
| 267 ASSERT(array->HasFastElements()); | 269 ASSERT(array->HasFastElements()); |
| 268 | 270 |
| 269 // Make sure we have space for the elements. | 271 // Make sure we have space for the elements. |
| 270 int len = Smi::cast(array->length())->value(); | 272 int len = Smi::cast(array->length())->value(); |
| 271 | 273 |
| 272 // Set new length. | 274 // Set new length. |
| 273 int new_length = len + args.length() - 1; | 275 int new_length = len + args.length() - 1; |
| 274 FixedArray* elms = FixedArray::cast(array->elements()); | 276 FixedArray* elms = FixedArray::cast(array->elements()); |
| 275 | 277 |
| 276 if (new_length <= elms->length()) { | 278 if (new_length <= elms->length()) { |
| 277 // Backing storage has extra space for the provided values. | 279 // Backing storage has extra space for the provided values. |
| 278 for (int index = 0; index < args.length() - 1; index++) { | 280 for (int index = 0; index < args.length() - 1; index++) { |
| 279 elms->set(index + len, args[index+1]); | 281 elms->set(index + len, args[index+1]); |
| 280 } | 282 } |
| 281 } else { | 283 } else { |
| 282 // New backing storage is needed. | 284 // New backing storage is needed. |
| 283 int capacity = new_length + (new_length >> 1) + 16; | 285 int capacity = new_length + (new_length >> 1) + 16; |
| 284 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); | 286 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); |
| 285 if (obj->IsFailure()) return obj; | 287 if (obj->IsFailure()) return obj; |
| 288 |
| 289 AssertNoAllocation no_gc; |
| 286 FixedArray* new_elms = FixedArray::cast(obj); | 290 FixedArray* new_elms = FixedArray::cast(obj); |
| 287 WriteBarrierMode mode = new_elms->GetWriteBarrierMode(); | 291 WriteBarrierMode mode = new_elms->GetWriteBarrierMode(no_gc); |
| 288 // Fill out the new array with old elements. | 292 // Fill out the new array with old elements. |
| 289 for (int i = 0; i < len; i++) new_elms->set(i, elms->get(i), mode); | 293 for (int i = 0; i < len; i++) new_elms->set(i, elms->get(i), mode); |
| 290 // Add the provided values. | 294 // Add the provided values. |
| 291 for (int index = 0; index < args.length() - 1; index++) { | 295 for (int index = 0; index < args.length() - 1; index++) { |
| 292 new_elms->set(index + len, args[index+1], mode); | 296 new_elms->set(index + len, args[index+1], mode); |
| 293 } | 297 } |
| 294 // Set the new backing storage. | 298 // Set the new backing storage. |
| 295 array->set_elements(new_elms); | 299 array->set_elements(new_elms); |
| 296 } | 300 } |
| 297 // Set the length. | 301 // Set the length. |
| 298 array->set_length(Smi::FromInt(new_length), SKIP_WRITE_BARRIER); | 302 array->set_length(Smi::FromInt(new_length)); |
| 299 return array->length(); | 303 return array->length(); |
| 300 } | 304 } |
| 301 | 305 |
| 302 | 306 |
| 303 BUILTIN(ArrayPop) { | 307 BUILTIN(ArrayPop) { |
| 304 JSArray* array = JSArray::cast(*args.receiver()); | 308 JSArray* array = JSArray::cast(*args.receiver()); |
| 305 ASSERT(array->HasFastElements()); | 309 ASSERT(array->HasFastElements()); |
| 306 Object* undefined = Heap::undefined_value(); | 310 Object* undefined = Heap::undefined_value(); |
| 307 | 311 |
| 308 int len = Smi::cast(array->length())->value(); | 312 int len = Smi::cast(array->length())->value(); |
| 309 if (len == 0) return undefined; | 313 if (len == 0) return undefined; |
| 310 | 314 |
| 311 // Get top element | 315 // Get top element |
| 312 FixedArray* elms = FixedArray::cast(array->elements()); | 316 FixedArray* elms = FixedArray::cast(array->elements()); |
| 313 Object* top = elms->get(len - 1); | 317 Object* top = elms->get(len - 1); |
| 314 | 318 |
| 315 // Set the length. | 319 // Set the length. |
| 316 array->set_length(Smi::FromInt(len - 1), SKIP_WRITE_BARRIER); | 320 array->set_length(Smi::FromInt(len - 1)); |
| 317 | 321 |
| 318 if (!top->IsTheHole()) { | 322 if (!top->IsTheHole()) { |
| 319 // Delete the top element. | 323 // Delete the top element. |
| 320 elms->set_the_hole(len - 1); | 324 elms->set_the_hole(len - 1); |
| 321 return top; | 325 return top; |
| 322 } | 326 } |
| 323 | 327 |
| 324 // Remember to check the prototype chain. | 328 // Remember to check the prototype chain. |
| 325 JSFunction* array_function = | 329 JSFunction* array_function = |
| 326 Top::context()->global_context()->array_function(); | 330 Top::context()->global_context()->array_function(); |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 if (entry->contains(pc)) { | 912 if (entry->contains(pc)) { |
| 909 return names_[i]; | 913 return names_[i]; |
| 910 } | 914 } |
| 911 } | 915 } |
| 912 } | 916 } |
| 913 return NULL; | 917 return NULL; |
| 914 } | 918 } |
| 915 | 919 |
| 916 | 920 |
| 917 } } // namespace v8::internal | 921 } } // namespace v8::internal |
| OLD | NEW |