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

Side by Side Diff: src/bootstrapper.cc

Issue 207613005: No longer OOM on invalid string length. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 Heap* heap = isolate_->heap(); 81 Heap* heap = isolate_->heap();
82 if (heap->natives_source_cache()->get(index)->IsUndefined()) { 82 if (heap->natives_source_cache()->get(index)->IsUndefined()) {
83 // We can use external strings for the natives. 83 // We can use external strings for the natives.
84 Vector<const char> source = Natives::GetRawScriptSource(index); 84 Vector<const char> source = Natives::GetRawScriptSource(index);
85 NativesExternalStringResource* resource = 85 NativesExternalStringResource* resource =
86 new NativesExternalStringResource(this, 86 new NativesExternalStringResource(this,
87 source.start(), 87 source.start(),
88 source.length()); 88 source.length());
89 Handle<String> source_code = 89 Handle<String> source_code =
90 isolate_->factory()->NewExternalStringFromAscii(resource); 90 isolate_->factory()->NewExternalStringFromAscii(resource);
91 // We do not expect this to throw an exception. Change this if it does.
92 CHECK_NOT_EMPTY_HANDLE(isolate_, source_code);
91 heap->natives_source_cache()->set(index, *source_code); 93 heap->natives_source_cache()->set(index, *source_code);
92 } 94 }
93 Handle<Object> cached_source(heap->natives_source_cache()->get(index), 95 Handle<Object> cached_source(heap->natives_source_cache()->get(index),
94 isolate_); 96 isolate_);
95 return Handle<String>::cast(cached_source); 97 return Handle<String>::cast(cached_source);
96 } 98 }
97 99
98 100
99 void Bootstrapper::Initialize(bool create_heap_objects) { 101 void Bootstrapper::Initialize(bool create_heap_objects) {
100 extensions_cache_.Initialize(isolate_, create_heap_objects); 102 extensions_cache_.Initialize(isolate_, create_heap_objects);
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 return CompileNative(isolate, name, source_code); 1461 return CompileNative(isolate, name, source_code);
1460 } 1462 }
1461 1463
1462 1464
1463 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { 1465 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
1464 Vector<const char> name = ExperimentalNatives::GetScriptName(index); 1466 Vector<const char> name = ExperimentalNatives::GetScriptName(index);
1465 Factory* factory = isolate->factory(); 1467 Factory* factory = isolate->factory();
1466 Handle<String> source_code = 1468 Handle<String> source_code =
1467 factory->NewStringFromAscii( 1469 factory->NewStringFromAscii(
1468 ExperimentalNatives::GetRawScriptSource(index)); 1470 ExperimentalNatives::GetRawScriptSource(index));
1471 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, source_code, false);
1469 return CompileNative(isolate, name, source_code); 1472 return CompileNative(isolate, name, source_code);
1470 } 1473 }
1471 1474
1472 1475
1473 bool Genesis::CompileNative(Isolate* isolate, 1476 bool Genesis::CompileNative(Isolate* isolate,
1474 Vector<const char> name, 1477 Vector<const char> name,
1475 Handle<String> source) { 1478 Handle<String> source) {
1476 HandleScope scope(isolate); 1479 HandleScope scope(isolate);
1477 #ifdef ENABLE_DEBUGGER_SUPPORT 1480 #ifdef ENABLE_DEBUGGER_SUPPORT
1478 isolate->debugger()->set_compiling_natives(true); 1481 isolate->debugger()->set_compiling_natives(true);
(...skipping 29 matching lines...) Expand all
1508 bool use_runtime_context) { 1511 bool use_runtime_context) {
1509 Factory* factory = isolate->factory(); 1512 Factory* factory = isolate->factory();
1510 HandleScope scope(isolate); 1513 HandleScope scope(isolate);
1511 Handle<SharedFunctionInfo> function_info; 1514 Handle<SharedFunctionInfo> function_info;
1512 1515
1513 // If we can't find the function in the cache, we compile a new 1516 // If we can't find the function in the cache, we compile a new
1514 // function and insert it into the cache. 1517 // function and insert it into the cache.
1515 if (cache == NULL || !cache->Lookup(name, &function_info)) { 1518 if (cache == NULL || !cache->Lookup(name, &function_info)) {
1516 ASSERT(source->IsOneByteRepresentation()); 1519 ASSERT(source->IsOneByteRepresentation());
1517 Handle<String> script_name = factory->NewStringFromUtf8(name); 1520 Handle<String> script_name = factory->NewStringFromUtf8(name);
1521 ASSERT(!script_name.is_null());
1518 function_info = Compiler::CompileScript( 1522 function_info = Compiler::CompileScript(
1519 source, 1523 source,
1520 script_name, 1524 script_name,
1521 0, 1525 0,
1522 0, 1526 0,
1523 false, 1527 false,
1524 top_context, 1528 top_context,
1525 extension, 1529 extension,
1526 NULL, 1530 NULL,
1527 NO_CACHED_DATA, 1531 NO_CACHED_DATA,
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 Factory* factory = isolate->factory(); 2080 Factory* factory = isolate->factory();
2077 Handle<GlobalObject> global(native_context->global_object()); 2081 Handle<GlobalObject> global(native_context->global_object());
2078 const char* period_pos = strchr(holder_expr, '.'); 2082 const char* period_pos = strchr(holder_expr, '.');
2079 if (period_pos == NULL) { 2083 if (period_pos == NULL) {
2080 return Handle<JSObject>::cast(GetProperty( 2084 return Handle<JSObject>::cast(GetProperty(
2081 isolate, global, factory->InternalizeUtf8String(holder_expr))); 2085 isolate, global, factory->InternalizeUtf8String(holder_expr)));
2082 } 2086 }
2083 ASSERT_EQ(".prototype", period_pos); 2087 ASSERT_EQ(".prototype", period_pos);
2084 Vector<const char> property(holder_expr, 2088 Vector<const char> property(holder_expr,
2085 static_cast<int>(period_pos - holder_expr)); 2089 static_cast<int>(period_pos - holder_expr));
2090 Handle<String> property_string = factory->InternalizeUtf8String(property);
2091 ASSERT(!property_string.is_null());
2086 Handle<JSFunction> function = Handle<JSFunction>::cast( 2092 Handle<JSFunction> function = Handle<JSFunction>::cast(
2087 GetProperty(isolate, global, factory->InternalizeUtf8String(property))); 2093 GetProperty(isolate, global, property_string));
2088 return Handle<JSObject>(JSObject::cast(function->prototype())); 2094 return Handle<JSObject>(JSObject::cast(function->prototype()));
2089 } 2095 }
2090 2096
2091 2097
2092 static void InstallBuiltinFunctionId(Handle<JSObject> holder, 2098 static void InstallBuiltinFunctionId(Handle<JSObject> holder,
2093 const char* function_name, 2099 const char* function_name,
2094 BuiltinFunctionId id) { 2100 BuiltinFunctionId id) {
2095 Factory* factory = holder->GetIsolate()->factory(); 2101 Factory* factory = holder->GetIsolate()->factory();
2096 Handle<String> name = factory->InternalizeUtf8String(function_name); 2102 Handle<String> name = factory->InternalizeUtf8String(function_name);
2097 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked(); 2103 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked();
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 // Install the extension's dependencies 2351 // Install the extension's dependencies
2346 for (int i = 0; i < extension->dependency_count(); i++) { 2352 for (int i = 0; i < extension->dependency_count(); i++) {
2347 if (!InstallExtension(isolate, 2353 if (!InstallExtension(isolate,
2348 extension->dependencies()[i], 2354 extension->dependencies()[i],
2349 extension_states)) { 2355 extension_states)) {
2350 return false; 2356 return false;
2351 } 2357 }
2352 } 2358 }
2353 Handle<String> source_code = 2359 Handle<String> source_code =
2354 isolate->factory()->NewExternalStringFromAscii(extension->source()); 2360 isolate->factory()->NewExternalStringFromAscii(extension->source());
2361 // We do not expect this to throw an exception. Change this if it does.
2362 CHECK_NOT_EMPTY_HANDLE(isolate, source_code);
2355 bool result = CompileScriptCached(isolate, 2363 bool result = CompileScriptCached(isolate,
2356 CStrVector(extension->name()), 2364 CStrVector(extension->name()),
2357 source_code, 2365 source_code,
2358 isolate->bootstrapper()->extensions_cache(), 2366 isolate->bootstrapper()->extensions_cache(),
2359 extension, 2367 extension,
2360 Handle<Context>(isolate->context()), 2368 Handle<Context>(isolate->context()),
2361 false); 2369 false);
2362 ASSERT(isolate->has_pending_exception() != result); 2370 ASSERT(isolate->has_pending_exception() != result);
2363 if (!result) { 2371 if (!result) {
2364 // We print out the name of the extension that fail to install. 2372 // We print out the name of the extension that fail to install.
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2750 return from + sizeof(NestingCounterType); 2758 return from + sizeof(NestingCounterType);
2751 } 2759 }
2752 2760
2753 2761
2754 // Called when the top-level V8 mutex is destroyed. 2762 // Called when the top-level V8 mutex is destroyed.
2755 void Bootstrapper::FreeThreadResources() { 2763 void Bootstrapper::FreeThreadResources() {
2756 ASSERT(!IsActive()); 2764 ASSERT(!IsActive());
2757 } 2765 }
2758 2766
2759 } } // namespace v8::internal 2767 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698