OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "bootstrapper.h" | 5 #include "bootstrapper.h" |
6 | 6 |
7 #include "accessors.h" | 7 #include "accessors.h" |
8 #include "isolate-inl.h" | 8 #include "isolate-inl.h" |
9 #include "natives.h" | 9 #include "natives.h" |
10 #include "snapshot.h" | 10 #include "snapshot.h" |
(...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 isolate); | 1510 isolate); |
1511 bool has_pending_exception; | 1511 bool has_pending_exception; |
1512 Execution::Call(isolate, fun, receiver, 0, NULL, &has_pending_exception); | 1512 Execution::Call(isolate, fun, receiver, 0, NULL, &has_pending_exception); |
1513 if (has_pending_exception) return false; | 1513 if (has_pending_exception) return false; |
1514 return true; | 1514 return true; |
1515 } | 1515 } |
1516 | 1516 |
1517 | 1517 |
1518 #define INSTALL_NATIVE(Type, name, var) \ | 1518 #define INSTALL_NATIVE(Type, name, var) \ |
1519 Handle<String> var##_name = \ | 1519 Handle<String> var##_name = \ |
1520 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR(name)); \ | 1520 factory()->InternalizeOneByteString(STATIC_ASCII_VECTOR(name)); \ |
1521 Handle<Object> var##_native = GlobalObject::GetPropertyNoExceptionThrown( \ | 1521 Handle<Object> var##_native = Object::GetProperty( \ |
1522 handle(native_context()->builtins()), var##_name); \ | 1522 handle(native_context()->builtins()), var##_name).ToHandleChecked(); \ |
1523 native_context()->set_##var(Type::cast(*var##_native)); | 1523 native_context()->set_##var(Type::cast(*var##_native)); |
1524 | 1524 |
1525 | 1525 |
1526 void Genesis::InstallNativeFunctions() { | 1526 void Genesis::InstallNativeFunctions() { |
1527 HandleScope scope(isolate()); | 1527 HandleScope scope(isolate()); |
1528 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); | 1528 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); |
1529 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); | 1529 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); |
1530 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); | 1530 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); |
1531 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); | 1531 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); |
1532 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); | 1532 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 Handle<JSFunction> string_function(native_context()->string_function()); | 1888 Handle<JSFunction> string_function(native_context()->string_function()); |
1889 ASSERT(JSObject::cast( | 1889 ASSERT(JSObject::cast( |
1890 string_function->initial_map()->prototype())->HasFastProperties()); | 1890 string_function->initial_map()->prototype())->HasFastProperties()); |
1891 native_context()->set_string_function_prototype_map( | 1891 native_context()->set_string_function_prototype_map( |
1892 HeapObject::cast(string_function->initial_map()->prototype())->map()); | 1892 HeapObject::cast(string_function->initial_map()->prototype())->map()); |
1893 | 1893 |
1894 // Install Function.prototype.call and apply. | 1894 // Install Function.prototype.call and apply. |
1895 { Handle<String> key = factory()->function_class_string(); | 1895 { Handle<String> key = factory()->function_class_string(); |
1896 Handle<JSFunction> function = | 1896 Handle<JSFunction> function = |
1897 Handle<JSFunction>::cast(Object::GetProperty( | 1897 Handle<JSFunction>::cast(Object::GetProperty( |
1898 isolate()->global_object(), key)); | 1898 isolate()->global_object(), key).ToHandleChecked()); |
1899 Handle<JSObject> proto = | 1899 Handle<JSObject> proto = |
1900 Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 1900 Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
1901 | 1901 |
1902 // Install the call and the apply functions. | 1902 // Install the call and the apply functions. |
1903 Handle<JSFunction> call = | 1903 Handle<JSFunction> call = |
1904 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, | 1904 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize, |
1905 Handle<JSObject>::null(), | 1905 Handle<JSObject>::null(), |
1906 Builtins::kFunctionCall, | 1906 Builtins::kFunctionCall, |
1907 false, false); | 1907 false, false); |
1908 Handle<JSFunction> apply = | 1908 Handle<JSFunction> apply = |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 if (period_pos == NULL) { | 2037 if (period_pos == NULL) { |
2038 return Handle<JSObject>::cast(Object::GetPropertyOrElement( | 2038 return Handle<JSObject>::cast(Object::GetPropertyOrElement( |
2039 global, factory->InternalizeUtf8String(holder_expr)).ToHandleChecked()); | 2039 global, factory->InternalizeUtf8String(holder_expr)).ToHandleChecked()); |
2040 } | 2040 } |
2041 ASSERT_EQ(".prototype", period_pos); | 2041 ASSERT_EQ(".prototype", period_pos); |
2042 Vector<const char> property(holder_expr, | 2042 Vector<const char> property(holder_expr, |
2043 static_cast<int>(period_pos - holder_expr)); | 2043 static_cast<int>(period_pos - holder_expr)); |
2044 Handle<String> property_string = factory->InternalizeUtf8String(property); | 2044 Handle<String> property_string = factory->InternalizeUtf8String(property); |
2045 ASSERT(!property_string.is_null()); | 2045 ASSERT(!property_string.is_null()); |
2046 Handle<JSFunction> function = Handle<JSFunction>::cast( | 2046 Handle<JSFunction> function = Handle<JSFunction>::cast( |
2047 Object::GetProperty(global, property_string)); | 2047 Object::GetProperty(global, property_string).ToHandleChecked()); |
2048 return Handle<JSObject>(JSObject::cast(function->prototype())); | 2048 return Handle<JSObject>(JSObject::cast(function->prototype())); |
2049 } | 2049 } |
2050 | 2050 |
2051 | 2051 |
2052 static void InstallBuiltinFunctionId(Handle<JSObject> holder, | 2052 static void InstallBuiltinFunctionId(Handle<JSObject> holder, |
2053 const char* function_name, | 2053 const char* function_name, |
2054 BuiltinFunctionId id) { | 2054 BuiltinFunctionId id) { |
2055 Factory* factory = holder->GetIsolate()->factory(); | 2055 Factory* factory = holder->GetIsolate()->factory(); |
2056 Handle<String> name = factory->InternalizeUtf8String(function_name); | 2056 Handle<String> name = factory->InternalizeUtf8String(function_name); |
2057 Handle<Object> function_object = Object::GetProperty(holder, name); | 2057 Handle<Object> function_object = |
2058 ASSERT(!function_object.is_null()); | 2058 Object::GetProperty(holder, name).ToHandleChecked(); |
2059 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); | 2059 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); |
2060 function->shared()->set_function_data(Smi::FromInt(id)); | 2060 function->shared()->set_function_data(Smi::FromInt(id)); |
2061 } | 2061 } |
2062 | 2062 |
2063 | 2063 |
2064 void Genesis::InstallBuiltinFunctionIds() { | 2064 void Genesis::InstallBuiltinFunctionIds() { |
2065 HandleScope scope(isolate()); | 2065 HandleScope scope(isolate()); |
2066 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ | 2066 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ |
2067 { \ | 2067 { \ |
2068 Handle<JSObject> holder = ResolveBuiltinIdHolder( \ | 2068 Handle<JSObject> holder = ResolveBuiltinIdHolder( \ |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2344 } | 2344 } |
2345 | 2345 |
2346 | 2346 |
2347 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { | 2347 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) { |
2348 HandleScope scope(isolate()); | 2348 HandleScope scope(isolate()); |
2349 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { | 2349 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) { |
2350 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); | 2350 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i); |
2351 Handle<String> name = | 2351 Handle<String> name = |
2352 factory()->InternalizeUtf8String(Builtins::GetName(id)); | 2352 factory()->InternalizeUtf8String(Builtins::GetName(id)); |
2353 Handle<Object> function_object = | 2353 Handle<Object> function_object = |
2354 GlobalObject::GetPropertyNoExceptionThrown(builtins, name); | 2354 Object::GetProperty(builtins, name).ToHandleChecked(); |
2355 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); | 2355 Handle<JSFunction> function = Handle<JSFunction>::cast(function_object); |
2356 builtins->set_javascript_builtin(id, *function); | 2356 builtins->set_javascript_builtin(id, *function); |
2357 if (!Compiler::EnsureCompiled(function, CLEAR_EXCEPTION)) { | 2357 if (!Compiler::EnsureCompiled(function, CLEAR_EXCEPTION)) { |
2358 return false; | 2358 return false; |
2359 } | 2359 } |
2360 builtins->set_javascript_builtin_code(id, function->shared()->code()); | 2360 builtins->set_javascript_builtin_code(id, function->shared()->code()); |
2361 } | 2361 } |
2362 return true; | 2362 return true; |
2363 } | 2363 } |
2364 | 2364 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2718 return from + sizeof(NestingCounterType); | 2718 return from + sizeof(NestingCounterType); |
2719 } | 2719 } |
2720 | 2720 |
2721 | 2721 |
2722 // Called when the top-level V8 mutex is destroyed. | 2722 // Called when the top-level V8 mutex is destroyed. |
2723 void Bootstrapper::FreeThreadResources() { | 2723 void Bootstrapper::FreeThreadResources() { |
2724 ASSERT(!IsActive()); | 2724 ASSERT(!IsActive()); |
2725 } | 2725 } |
2726 | 2726 |
2727 } } // namespace v8::internal | 2727 } } // namespace v8::internal |
OLD | NEW |