| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 238   // 'from'. | 238   // 'from'. | 
| 239   void TransferObject(Handle<JSObject> from, Handle<JSObject> to); | 239   void TransferObject(Handle<JSObject> from, Handle<JSObject> to); | 
| 240   void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); | 240   void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); | 
| 241   void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); | 241   void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); | 
| 242 | 242 | 
| 243   Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( | 243   Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( | 
| 244       bool make_prototype_read_only, | 244       bool make_prototype_read_only, | 
| 245       bool make_prototype_enumerable = false); | 245       bool make_prototype_enumerable = false); | 
| 246   void MakeFunctionInstancePrototypeWritable(); | 246   void MakeFunctionInstancePrototypeWritable(); | 
| 247 | 247 | 
| 248   Handle<JSFunction> MakeFunctionForBuiltin(Handle<String> name, |  | 
| 249                                             Handle<Code> code); |  | 
| 250 |  | 
| 251   void OverrideWithSpecialFunction(Handle<JSObject> prototype, |  | 
| 252                                    const char* name, |  | 
| 253                                    Handle<Code> code); |  | 
| 254 |  | 
| 255   void InstallSpecialFunctions(); |  | 
| 256 |  | 
| 257   static bool CompileBuiltin(int index); | 248   static bool CompileBuiltin(int index); | 
| 258   static bool CompileNative(Vector<const char> name, Handle<String> source); | 249   static bool CompileNative(Vector<const char> name, Handle<String> source); | 
| 259   static bool CompileScriptCached(Vector<const char> name, | 250   static bool CompileScriptCached(Vector<const char> name, | 
| 260                                   Handle<String> source, | 251                                   Handle<String> source, | 
| 261                                   SourceCodeCache* cache, | 252                                   SourceCodeCache* cache, | 
| 262                                   v8::Extension* extension, | 253                                   v8::Extension* extension, | 
| 263                                   bool use_runtime_context); | 254                                   bool use_runtime_context); | 
| 264 | 255 | 
| 265   Handle<Context> result_; | 256   Handle<Context> result_; | 
| 266 }; | 257 }; | 
| (...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1451   HandleScope scope; | 1442   HandleScope scope; | 
| 1452 | 1443 | 
| 1453   Handle<DescriptorArray> function_map_descriptors = | 1444   Handle<DescriptorArray> function_map_descriptors = | 
| 1454       ComputeFunctionInstanceDescriptor(false); | 1445       ComputeFunctionInstanceDescriptor(false); | 
| 1455   Handle<Map> fm = Factory::CopyMapDropDescriptors(Top::function_map()); | 1446   Handle<Map> fm = Factory::CopyMapDropDescriptors(Top::function_map()); | 
| 1456   fm->set_instance_descriptors(*function_map_descriptors); | 1447   fm->set_instance_descriptors(*function_map_descriptors); | 
| 1457   Top::context()->global_context()->set_function_map(*fm); | 1448   Top::context()->global_context()->set_function_map(*fm); | 
| 1458 } | 1449 } | 
| 1459 | 1450 | 
| 1460 | 1451 | 
| 1461 Handle<JSFunction> Genesis::MakeFunctionForBuiltin(Handle<String> name, |  | 
| 1462                                                    Handle<Code> code) { |  | 
| 1463   Handle<JSFunction> optimized = Factory::NewFunction(name, |  | 
| 1464                                                       JS_OBJECT_TYPE, |  | 
| 1465                                                       JSObject::kHeaderSize, |  | 
| 1466                                                       code, |  | 
| 1467                                                       false); |  | 
| 1468   optimized->shared()->DontAdaptArguments(); |  | 
| 1469   return optimized; |  | 
| 1470 } |  | 
| 1471 |  | 
| 1472 |  | 
| 1473 void Genesis::OverrideWithSpecialFunction(Handle<JSObject> prototype, |  | 
| 1474                                           const char* name, |  | 
| 1475                                           Handle<Code> code) { |  | 
| 1476   Handle<String> key = Factory::LookupAsciiSymbol(name); |  | 
| 1477   Handle<Object> old_value = GetProperty(prototype, key); |  | 
| 1478   // Check if the function is present in the first place. |  | 
| 1479   // For example, FLAG_natives_file could affect if Array functions |  | 
| 1480   // are installed at all. |  | 
| 1481   if (!old_value->IsJSFunction()) return; |  | 
| 1482   int old_length = Handle<JSFunction>::cast(old_value)->shared()->length(); |  | 
| 1483   Handle<JSFunction> optimized = MakeFunctionForBuiltin(key, code); |  | 
| 1484   optimized->shared()->set_length(old_length); |  | 
| 1485   SetProperty(prototype, key, optimized, NONE); |  | 
| 1486 } |  | 
| 1487 |  | 
| 1488 |  | 
| 1489 void Genesis::InstallSpecialFunctions() { |  | 
| 1490   HandleScope scope; |  | 
| 1491   Handle<JSObject> global = Handle<JSObject>(global_context()->global()); |  | 
| 1492   // Add special versions for some Array.prototype functions. |  | 
| 1493   Handle<JSFunction> function = |  | 
| 1494       Handle<JSFunction>( |  | 
| 1495           JSFunction::cast(global->GetProperty(Heap::Array_symbol()))); |  | 
| 1496   Handle<JSObject> visible_prototype = |  | 
| 1497       Handle<JSObject>(JSObject::cast(function->prototype())); |  | 
| 1498   // Remember to put those specializations on the hidden prototype if present. |  | 
| 1499   Handle<JSObject> special_prototype; |  | 
| 1500   Handle<Object> superproto(visible_prototype->GetPrototype()); |  | 
| 1501   if (superproto->IsJSObject() && |  | 
| 1502       JSObject::cast(*superproto)->map()->is_hidden_prototype()) { |  | 
| 1503     special_prototype = Handle<JSObject>::cast(superproto); |  | 
| 1504   } else { |  | 
| 1505     special_prototype = visible_prototype; |  | 
| 1506   } |  | 
| 1507   OverrideWithSpecialFunction( |  | 
| 1508       special_prototype, "pop", |  | 
| 1509       Handle<Code>(Builtins::builtin(Builtins::ArrayPop))); |  | 
| 1510   OverrideWithSpecialFunction( |  | 
| 1511       special_prototype, "push", |  | 
| 1512       Handle<Code>(Builtins::builtin(Builtins::ArrayPush))); |  | 
| 1513   OverrideWithSpecialFunction( |  | 
| 1514       special_prototype, "shift", |  | 
| 1515       Handle<Code>(Builtins::builtin(Builtins::ArrayShift))); |  | 
| 1516   OverrideWithSpecialFunction( |  | 
| 1517       special_prototype, "unshift", |  | 
| 1518       Handle<Code>(Builtins::builtin(Builtins::ArrayUnshift))); |  | 
| 1519   OverrideWithSpecialFunction( |  | 
| 1520       special_prototype, "slice", |  | 
| 1521       Handle<Code>(Builtins::builtin(Builtins::ArraySlice))); |  | 
| 1522   OverrideWithSpecialFunction( |  | 
| 1523       special_prototype, "splice", |  | 
| 1524       Handle<Code>(Builtins::builtin(Builtins::ArraySplice))); |  | 
| 1525 } |  | 
| 1526 |  | 
| 1527 |  | 
| 1528 Genesis::Genesis(Handle<Object> global_object, | 1452 Genesis::Genesis(Handle<Object> global_object, | 
| 1529                  v8::Handle<v8::ObjectTemplate> global_template, | 1453                  v8::Handle<v8::ObjectTemplate> global_template, | 
| 1530                  v8::ExtensionConfiguration* extensions) { | 1454                  v8::ExtensionConfiguration* extensions) { | 
| 1531   // Link this genesis object into the stacked genesis chain. This | 1455   // Link this genesis object into the stacked genesis chain. This | 
| 1532   // must be done before any early exits because the destructor | 1456   // must be done before any early exits because the destructor | 
| 1533   // will always do unlinking. | 1457   // will always do unlinking. | 
| 1534   previous_ = current_; | 1458   previous_ = current_; | 
| 1535   current_  = this; | 1459   current_  = this; | 
| 1536   result_ = Handle<Context>::null(); | 1460   result_ = Handle<Context>::null(); | 
| 1537 | 1461 | 
| 1538   // If V8 isn't running and cannot be initialized, just return. | 1462   // If V8 isn't running and cannot be initialized, just return. | 
| 1539   if (!V8::IsRunning() && !V8::Initialize(NULL)) return; | 1463   if (!V8::IsRunning() && !V8::Initialize(NULL)) return; | 
| 1540 | 1464 | 
| 1541   // Before creating the roots we must save the context and restore it | 1465   // Before creating the roots we must save the context and restore it | 
| 1542   // on all function exits. | 1466   // on all function exits. | 
| 1543   HandleScope scope; | 1467   HandleScope scope; | 
| 1544   SaveContext context; | 1468   SaveContext context; | 
| 1545 | 1469 | 
| 1546   CreateRoots(global_template, global_object); | 1470   CreateRoots(global_template, global_object); | 
| 1547 | 1471 | 
| 1548   if (!InstallNatives()) return; | 1472   if (!InstallNatives()) return; | 
| 1549 | 1473 | 
| 1550   MakeFunctionInstancePrototypeWritable(); | 1474   MakeFunctionInstancePrototypeWritable(); | 
| 1551   InstallSpecialFunctions(); |  | 
| 1552 | 1475 | 
| 1553   if (!ConfigureGlobalObjects(global_template)) return; | 1476   if (!ConfigureGlobalObjects(global_template)) return; | 
| 1554 | 1477 | 
| 1555   if (!InstallExtensions(extensions)) return; | 1478   if (!InstallExtensions(extensions)) return; | 
| 1556 | 1479 | 
| 1557   if (!InstallSpecialObjects()) return; | 1480   if (!InstallSpecialObjects()) return; | 
| 1558 | 1481 | 
| 1559   result_ = global_context_; | 1482   result_ = global_context_; | 
| 1560 } | 1483 } | 
| 1561 | 1484 | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1600 } | 1523 } | 
| 1601 | 1524 | 
| 1602 | 1525 | 
| 1603 // Restore statics that are thread local. | 1526 // Restore statics that are thread local. | 
| 1604 char* Genesis::RestoreState(char* from) { | 1527 char* Genesis::RestoreState(char* from) { | 
| 1605   current_ = *reinterpret_cast<Genesis**>(from); | 1528   current_ = *reinterpret_cast<Genesis**>(from); | 
| 1606   return from + sizeof(current_); | 1529   return from + sizeof(current_); | 
| 1607 } | 1530 } | 
| 1608 | 1531 | 
| 1609 } }  // namespace v8::internal | 1532 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|