Chromium Code Reviews| Index: src/api.cc |
| diff --git a/src/api.cc b/src/api.cc |
| index 8238922453bfb48130955ebbf8eb8c63e5e72b36..de828e9404c33b727be91f116f677a1f0f9e50a6 100644 |
| --- a/src/api.cc |
| +++ b/src/api.cc |
| @@ -1699,7 +1699,7 @@ Local<UnboundScript> ScriptCompiler::CompileUnbound( |
| Isolate* v8_isolate, |
| Source* source, |
| CompileOptions options) { |
| - i::ScriptData* script_data_impl = NULL; |
| + i::ScriptData* script_data = NULL; |
| i::CachedDataMode cached_data_mode = i::NO_CACHED_DATA; |
| i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| ON_BAILOUT(isolate, "v8::ScriptCompiler::CompileUnbound()", |
| @@ -1707,35 +1707,11 @@ Local<UnboundScript> ScriptCompiler::CompileUnbound( |
| if (options & kProduceDataToCache) { |
| cached_data_mode = i::PRODUCE_CACHED_DATA; |
| ASSERT(source->cached_data == NULL); |
|
marja
2014/07/09 14:42:30
Shouldn't you crash if source->cached_data != NULL
Yang
2014/07/10 08:28:45
Done.
|
| - if (source->cached_data) { |
| - // Asked to produce cached data even though there is some already -> not |
| - // good. Fail the compilation. |
| - EXCEPTION_PREAMBLE(isolate); |
| - i::Handle<i::Object> result = isolate->factory()->NewSyntaxError( |
| - "invalid_cached_data", isolate->factory()->NewJSArray(0)); |
| - isolate->Throw(*result); |
| - isolate->ReportPendingMessages(); |
| - has_pending_exception = true; |
| - EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); |
| - } |
| } else if (source->cached_data) { |
| cached_data_mode = i::CONSUME_CACHED_DATA; |
| - // ScriptData takes care of aligning, in case the data is not aligned |
| - // correctly. |
| - script_data_impl = i::ScriptData::New( |
| - reinterpret_cast<const char*>(source->cached_data->data), |
| - source->cached_data->length); |
| - // If the cached data is not valid, fail the compilation. |
| - if (script_data_impl == NULL || !script_data_impl->SanityCheck()) { |
| - EXCEPTION_PREAMBLE(isolate); |
| - i::Handle<i::Object> result = isolate->factory()->NewSyntaxError( |
| - "invalid_cached_data", isolate->factory()->NewJSArray(0)); |
| - isolate->Throw(*result); |
| - isolate->ReportPendingMessages(); |
| - delete script_data_impl; |
| - has_pending_exception = true; |
| - EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); |
| - } |
| + // ScriptData takes care of pointer-aligning the data. |
| + script_data = new i::ScriptData(source->cached_data->data, |
| + source->cached_data->length); |
| } |
| i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); |
| @@ -1763,36 +1739,28 @@ Local<UnboundScript> ScriptCompiler::CompileUnbound( |
| source->resource_is_shared_cross_origin == v8::True(v8_isolate); |
| } |
| EXCEPTION_PREAMBLE(isolate); |
| - i::Handle<i::SharedFunctionInfo> result = |
| - i::Compiler::CompileScript(str, |
| - name_obj, |
| - line_offset, |
| - column_offset, |
| - is_shared_cross_origin, |
| - isolate->global_context(), |
| - NULL, |
| - &script_data_impl, |
| - cached_data_mode, |
| - i::NOT_NATIVES_CODE); |
| + i::Handle<i::SharedFunctionInfo> result = i::Compiler::CompileScript( |
| + str, name_obj, line_offset, column_offset, is_shared_cross_origin, |
| + isolate->global_context(), NULL, &script_data, cached_data_mode, |
| + i::NOT_NATIVES_CODE); |
| has_pending_exception = result.is_null(); |
| if (has_pending_exception && cached_data_mode == i::CONSUME_CACHED_DATA) { |
| // This case won't happen during normal operation; we have compiled |
| // successfully and produced cached data, and but the second compilation |
| // of the same source code fails. |
| - delete script_data_impl; |
| - script_data_impl = NULL; |
| + delete script_data; |
| + script_data = NULL; |
| } |
| EXCEPTION_BAILOUT_CHECK(isolate, Local<UnboundScript>()); |
| raw_result = *result; |
| - if ((options & kProduceDataToCache) && script_data_impl != NULL) { |
| + if ((options & kProduceDataToCache) && script_data != NULL) { |
| // script_data_impl now contains the data that was generated. source will |
| // take the ownership. |
| source->cached_data = new CachedData( |
| - reinterpret_cast<const uint8_t*>(script_data_impl->Data()), |
| - script_data_impl->Length(), CachedData::BufferOwned); |
| - script_data_impl->owns_store_ = false; |
| + script_data->data(), script_data->length(), CachedData::BufferOwned); |
| + script_data->ReleaseDataOwnership(); |
| } |
| - delete script_data_impl; |
| + delete script_data; |
| } |
| i::Handle<i::SharedFunctionInfo> result(raw_result, isolate); |
| return ToApiHandle<UnboundScript>(result); |