Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: src/bootstrapper.cc

Issue 606017: Introduce builtin for Array.shift function. (Closed)
Patch Set: Next round of Mads' comments Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/builtins.h » ('j') | test/mjsunit/array-shift.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 new_array->set(len+1, *value); 1466 new_array->set(len+1, *value);
1467 new_array->set(len+2, *optimized); 1467 new_array->set(len+2, *optimized);
1468 global_context()->set_special_function_table(*new_array); 1468 global_context()->set_special_function_table(*new_array);
1469 } 1469 }
1470 } 1470 }
1471 1471
1472 1472
1473 void Genesis::BuildSpecialFunctionTable() { 1473 void Genesis::BuildSpecialFunctionTable() {
1474 HandleScope scope; 1474 HandleScope scope;
1475 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); 1475 Handle<JSObject> global = Handle<JSObject>(global_context()->global());
1476 // Add special versions for Array.prototype.pop and push. 1476 // Add special versions for some Array.prototype functions.
1477 Handle<JSFunction> function = 1477 Handle<JSFunction> function =
1478 Handle<JSFunction>( 1478 Handle<JSFunction>(
1479 JSFunction::cast(global->GetProperty(Heap::Array_symbol()))); 1479 JSFunction::cast(global->GetProperty(Heap::Array_symbol())));
1480 Handle<JSObject> visible_prototype = 1480 Handle<JSObject> visible_prototype =
1481 Handle<JSObject>(JSObject::cast(function->prototype())); 1481 Handle<JSObject>(JSObject::cast(function->prototype()));
1482 // Remember to put push and pop on the hidden prototype if it's there. 1482 // Remember to put those specializations on the hidden prototype if present.
1483 Handle<JSObject> push_and_pop_prototype; 1483 Handle<JSObject> special_prototype;
1484 Handle<Object> superproto(visible_prototype->GetPrototype()); 1484 Handle<Object> superproto(visible_prototype->GetPrototype());
1485 if (superproto->IsJSObject() && 1485 if (superproto->IsJSObject() &&
1486 JSObject::cast(*superproto)->map()->is_hidden_prototype()) { 1486 JSObject::cast(*superproto)->map()->is_hidden_prototype()) {
1487 push_and_pop_prototype = Handle<JSObject>::cast(superproto); 1487 special_prototype = Handle<JSObject>::cast(superproto);
1488 } else { 1488 } else {
1489 push_and_pop_prototype = visible_prototype; 1489 special_prototype = visible_prototype;
1490 } 1490 }
1491 AddSpecialFunction(push_and_pop_prototype, "pop", 1491 AddSpecialFunction(special_prototype, "pop",
1492 Handle<Code>(Builtins::builtin(Builtins::ArrayPop))); 1492 Handle<Code>(Builtins::builtin(Builtins::ArrayPop)));
1493 AddSpecialFunction(push_and_pop_prototype, "push", 1493 AddSpecialFunction(special_prototype, "push",
1494 Handle<Code>(Builtins::builtin(Builtins::ArrayPush))); 1494 Handle<Code>(Builtins::builtin(Builtins::ArrayPush)));
1495 AddSpecialFunction(special_prototype, "shift",
1496 Handle<Code>(Builtins::builtin(Builtins::ArrayShift)));
1495 } 1497 }
1496 1498
1497 1499
1498 Genesis::Genesis(Handle<Object> global_object, 1500 Genesis::Genesis(Handle<Object> global_object,
1499 v8::Handle<v8::ObjectTemplate> global_template, 1501 v8::Handle<v8::ObjectTemplate> global_template,
1500 v8::ExtensionConfiguration* extensions) { 1502 v8::ExtensionConfiguration* extensions) {
1501 // Link this genesis object into the stacked genesis chain. This 1503 // Link this genesis object into the stacked genesis chain. This
1502 // must be done before any early exits because the destructor 1504 // must be done before any early exits because the destructor
1503 // will always do unlinking. 1505 // will always do unlinking.
1504 previous_ = current_; 1506 previous_ = current_;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 } 1572 }
1571 1573
1572 1574
1573 // Restore statics that are thread local. 1575 // Restore statics that are thread local.
1574 char* Genesis::RestoreState(char* from) { 1576 char* Genesis::RestoreState(char* from) {
1575 current_ = *reinterpret_cast<Genesis**>(from); 1577 current_ = *reinterpret_cast<Genesis**>(from);
1576 return from + sizeof(current_); 1578 return from + sizeof(current_);
1577 } 1579 }
1578 1580
1579 } } // namespace v8::internal 1581 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/builtins.h » ('j') | test/mjsunit/array-shift.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698