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

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: rebase + addressed nits 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
« no previous file with comments | « src/bootstrapper.h ('k') | src/contexts.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 return CompileNative(isolate, name, source_code); 1458 return CompileNative(isolate, name, source_code);
1457 } 1459 }
1458 1460
1459 1461
1460 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { 1462 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) {
1461 Vector<const char> name = ExperimentalNatives::GetScriptName(index); 1463 Vector<const char> name = ExperimentalNatives::GetScriptName(index);
1462 Factory* factory = isolate->factory(); 1464 Factory* factory = isolate->factory();
1463 Handle<String> source_code = 1465 Handle<String> source_code =
1464 factory->NewStringFromAscii( 1466 factory->NewStringFromAscii(
1465 ExperimentalNatives::GetRawScriptSource(index)); 1467 ExperimentalNatives::GetRawScriptSource(index));
1468 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, source_code, false);
1466 return CompileNative(isolate, name, source_code); 1469 return CompileNative(isolate, name, source_code);
1467 } 1470 }
1468 1471
1469 1472
1470 bool Genesis::CompileNative(Isolate* isolate, 1473 bool Genesis::CompileNative(Isolate* isolate,
1471 Vector<const char> name, 1474 Vector<const char> name,
1472 Handle<String> source) { 1475 Handle<String> source) {
1473 HandleScope scope(isolate); 1476 HandleScope scope(isolate);
1474 #ifdef ENABLE_DEBUGGER_SUPPORT 1477 #ifdef ENABLE_DEBUGGER_SUPPORT
1475 isolate->debugger()->set_compiling_natives(true); 1478 isolate->debugger()->set_compiling_natives(true);
(...skipping 29 matching lines...) Expand all
1505 bool use_runtime_context) { 1508 bool use_runtime_context) {
1506 Factory* factory = isolate->factory(); 1509 Factory* factory = isolate->factory();
1507 HandleScope scope(isolate); 1510 HandleScope scope(isolate);
1508 Handle<SharedFunctionInfo> function_info; 1511 Handle<SharedFunctionInfo> function_info;
1509 1512
1510 // If we can't find the function in the cache, we compile a new 1513 // If we can't find the function in the cache, we compile a new
1511 // function and insert it into the cache. 1514 // function and insert it into the cache.
1512 if (cache == NULL || !cache->Lookup(name, &function_info)) { 1515 if (cache == NULL || !cache->Lookup(name, &function_info)) {
1513 ASSERT(source->IsOneByteRepresentation()); 1516 ASSERT(source->IsOneByteRepresentation());
1514 Handle<String> script_name = factory->NewStringFromUtf8(name); 1517 Handle<String> script_name = factory->NewStringFromUtf8(name);
1518 ASSERT(!script_name.is_null());
1515 function_info = Compiler::CompileScript( 1519 function_info = Compiler::CompileScript(
1516 source, 1520 source,
1517 script_name, 1521 script_name,
1518 0, 1522 0,
1519 0, 1523 0,
1520 false, 1524 false,
1521 top_context, 1525 top_context,
1522 extension, 1526 extension,
1523 NULL, 1527 NULL,
1524 NO_CACHED_DATA, 1528 NO_CACHED_DATA,
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 Factory* factory = isolate->factory(); 2077 Factory* factory = isolate->factory();
2074 Handle<GlobalObject> global(native_context->global_object()); 2078 Handle<GlobalObject> global(native_context->global_object());
2075 const char* period_pos = strchr(holder_expr, '.'); 2079 const char* period_pos = strchr(holder_expr, '.');
2076 if (period_pos == NULL) { 2080 if (period_pos == NULL) {
2077 return Handle<JSObject>::cast(GetProperty( 2081 return Handle<JSObject>::cast(GetProperty(
2078 isolate, global, factory->InternalizeUtf8String(holder_expr))); 2082 isolate, global, factory->InternalizeUtf8String(holder_expr)));
2079 } 2083 }
2080 ASSERT_EQ(".prototype", period_pos); 2084 ASSERT_EQ(".prototype", period_pos);
2081 Vector<const char> property(holder_expr, 2085 Vector<const char> property(holder_expr,
2082 static_cast<int>(period_pos - holder_expr)); 2086 static_cast<int>(period_pos - holder_expr));
2087 Handle<String> property_string = factory->InternalizeUtf8String(property);
2088 ASSERT(!property_string.is_null());
2083 Handle<JSFunction> function = Handle<JSFunction>::cast( 2089 Handle<JSFunction> function = Handle<JSFunction>::cast(
2084 GetProperty(isolate, global, factory->InternalizeUtf8String(property))); 2090 GetProperty(isolate, global, property_string));
2085 return Handle<JSObject>(JSObject::cast(function->prototype())); 2091 return Handle<JSObject>(JSObject::cast(function->prototype()));
2086 } 2092 }
2087 2093
2088 2094
2089 static void InstallBuiltinFunctionId(Handle<JSObject> holder, 2095 static void InstallBuiltinFunctionId(Handle<JSObject> holder,
2090 const char* function_name, 2096 const char* function_name,
2091 BuiltinFunctionId id) { 2097 BuiltinFunctionId id) {
2092 Factory* factory = holder->GetIsolate()->factory(); 2098 Factory* factory = holder->GetIsolate()->factory();
2093 Handle<String> name = factory->InternalizeUtf8String(function_name); 2099 Handle<String> name = factory->InternalizeUtf8String(function_name);
2094 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked(); 2100 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked();
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 // Install the extension's dependencies 2348 // Install the extension's dependencies
2343 for (int i = 0; i < extension->dependency_count(); i++) { 2349 for (int i = 0; i < extension->dependency_count(); i++) {
2344 if (!InstallExtension(isolate, 2350 if (!InstallExtension(isolate,
2345 extension->dependencies()[i], 2351 extension->dependencies()[i],
2346 extension_states)) { 2352 extension_states)) {
2347 return false; 2353 return false;
2348 } 2354 }
2349 } 2355 }
2350 Handle<String> source_code = 2356 Handle<String> source_code =
2351 isolate->factory()->NewExternalStringFromAscii(extension->source()); 2357 isolate->factory()->NewExternalStringFromAscii(extension->source());
2358 // We do not expect this to throw an exception. Change this if it does.
2359 CHECK_NOT_EMPTY_HANDLE(isolate, source_code);
2352 bool result = CompileScriptCached(isolate, 2360 bool result = CompileScriptCached(isolate,
2353 CStrVector(extension->name()), 2361 CStrVector(extension->name()),
2354 source_code, 2362 source_code,
2355 isolate->bootstrapper()->extensions_cache(), 2363 isolate->bootstrapper()->extensions_cache(),
2356 extension, 2364 extension,
2357 Handle<Context>(isolate->context()), 2365 Handle<Context>(isolate->context()),
2358 false); 2366 false);
2359 ASSERT(isolate->has_pending_exception() != result); 2367 ASSERT(isolate->has_pending_exception() != result);
2360 if (!result) { 2368 if (!result) {
2361 // We print out the name of the extension that fail to install. 2369 // We print out the name of the extension that fail to install.
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2747 return from + sizeof(NestingCounterType); 2755 return from + sizeof(NestingCounterType);
2748 } 2756 }
2749 2757
2750 2758
2751 // Called when the top-level V8 mutex is destroyed. 2759 // Called when the top-level V8 mutex is destroyed.
2752 void Bootstrapper::FreeThreadResources() { 2760 void Bootstrapper::FreeThreadResources() {
2753 ASSERT(!IsActive()); 2761 ASSERT(!IsActive());
2754 } 2762 }
2755 2763
2756 } } // namespace v8::internal 2764 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/contexts.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698