From b27431d52f0ddc556aa2a748ddf5021ea69d0e5c Mon Sep 17 00:00:00 2001 From: vogelheim Date: Thu, 4 Dec 2014 10:51:15 -0800 Subject: [PATCH] Cleanup: Remove NativesCollection<.>::*Raw* methods. These methods for used for compressed libraries, where GetSource* functions contained the compressed sources and [GS]etRawSource* the uncompressed sources. This is dead code since the API no longer supports compression. (If you need/want compressed sources, use the external startup data and compress/uncompress on the Embedder's side.) BUG= Review URL: https://codereview.chromium.org/772853003 Cr-Commit-Position: refs/heads/master@{#25666} --- src/bootstrapper.cc | 6 +++--- src/d8.cc | 2 +- src/natives-external.cc | 38 ++++++++++------------------------- src/natives.h | 10 ++-------- src/serialize.cc | 2 +- test/cctest/test-log.cc | 5 ++--- tools/js2c.py | 53 ++++++++++--------------------------------------- 7 files changed, 31 insertions(+), 85 deletions(-) diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 53733ff..3650d94 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -48,7 +48,7 @@ Handle Bootstrapper::NativesSourceLookup(int index) { Heap* heap = isolate_->heap(); if (heap->natives_source_cache()->get(index)->IsUndefined()) { // We can use external strings for the natives. - Vector source = Natives::GetRawScriptSource(index); + Vector source = Natives::GetScriptSource(index); NativesExternalStringResource* resource = new NativesExternalStringResource(this, source.start(), @@ -1394,8 +1394,8 @@ bool Genesis::CompileExperimentalBuiltin(Isolate* isolate, int index) { Factory* factory = isolate->factory(); Handle source_code; ASSIGN_RETURN_ON_EXCEPTION_VALUE( - isolate, source_code, factory->NewStringFromAscii( - ExperimentalNatives::GetRawScriptSource(index)), + isolate, source_code, + factory->NewStringFromAscii(ExperimentalNatives::GetScriptSource(index)), false); return CompileNative(isolate, name, source_code); } diff --git a/src/d8.cc b/src/d8.cc index e18f2da..0541d25 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -851,7 +851,7 @@ void Shell::InstallUtilityScript(Isolate* isolate) { // Run the d8 shell utility script in the utility context int source_index = i::NativesCollection::GetIndex("d8"); i::Vector shell_source = - i::NativesCollection::GetRawScriptSource(source_index); + i::NativesCollection::GetScriptSource(source_index); i::Vector shell_source_name = i::NativesCollection::GetScriptName(source_index); Handle source = diff --git a/src/natives-external.cc b/src/natives-external.cc index 75e866b..b0e1606 100644 --- a/src/natives-external.cc +++ b/src/natives-external.cc @@ -32,12 +32,12 @@ class NativesStore { int GetBuiltinsCount() { return native_ids_.length(); } int GetDebuggerCount() { return debugger_count_; } - Vector GetScriptName(int index) { return native_names_[index]; } - - Vector GetRawScriptSource(int index) { + Vector GetScriptSource(int index) { return native_source_[index]; } + Vector GetScriptName(int index) { return native_names_[index]; } + int GetIndex(const char* id) { for (int i = 0; i < native_ids_.length(); ++i) { int native_id_length = native_ids_[i].length(); @@ -50,14 +50,9 @@ class NativesStore { return -1; } - int GetRawScriptsSize() { - DCHECK(false); // Used for compression. Doesn't really make sense here. - return 0; - } - - Vector GetScriptsSource() { - DCHECK(false); // Used for compression. Doesn't really make sense here. - return Vector(); + Vector GetScriptsSource() { + DCHECK(false); // Not implemented. + return Vector(); } static NativesStore* MakeFromScriptsSource(SnapshotByteSource* source) { @@ -177,14 +172,9 @@ int NativesCollection::GetIndex(const char* name) { return NativesHolder::get()->GetIndex(name); } -template -int NativesCollection::GetRawScriptsSize() { - return NativesHolder::get()->GetRawScriptsSize(); -} - -template -Vector NativesCollection::GetRawScriptSource(int index) { - return NativesHolder::get()->GetRawScriptSource(index); +template +Vector NativesCollection::GetScriptSource(int index) { + return NativesHolder::get()->GetScriptSource(index); } template @@ -192,17 +182,11 @@ Vector NativesCollection::GetScriptName(int index) { return NativesHolder::get()->GetScriptName(index); } -template -Vector NativesCollection::GetScriptsSource() { +template +Vector NativesCollection::GetScriptsSource() { return NativesHolder::get()->GetScriptsSource(); } -template -void NativesCollection::SetRawScriptsSource( - Vector raw_source) { - CHECK(false); // Use SetNativesFromFile for this implementation. -} - // The compiler can't 'see' all uses of the static methods and hence // my chose to elide them. This we'll explicitly instantiate these. diff --git a/src/natives.h b/src/natives.h index 6ddedf0..7ce7213 100644 --- a/src/natives.h +++ b/src/natives.h @@ -12,10 +12,6 @@ namespace v8 { class StartupData; } // Forward declaration. namespace v8 { namespace internal { -typedef bool (*NativeSourceCallback)(Vector name, - Vector source, - int index); - enum NativeType { CORE, EXPERIMENTAL, D8, TEST }; @@ -33,11 +29,9 @@ class NativesCollection { // non-debugger scripts have an index in the interval [GetDebuggerCount(), // GetNativesCount()). static int GetIndex(const char* name); - static int GetRawScriptsSize(); - static Vector GetRawScriptSource(int index); + static Vector GetScriptSource(int index); static Vector GetScriptName(int index); - static Vector GetScriptsSource(); - static void SetRawScriptsSource(Vector raw_source); + static Vector GetScriptsSource(); }; typedef NativesCollection Natives; diff --git a/src/serialize.cc b/src/serialize.cc index e6aae7f..48f05d4 100644 --- a/src/serialize.cc +++ b/src/serialize.cc @@ -1248,7 +1248,7 @@ void Deserializer::ReadData(Object** current, Object** limit, int source_space, case kNativesStringResource: { int index = source_->Get(); - Vector source_vector = Natives::GetRawScriptSource(index); + Vector source_vector = Natives::GetScriptSource(index); NativesExternalStringResource* resource = new NativesExternalStringResource(isolate->bootstrapper(), source_vector.start(), diff --git a/test/cctest/test-log.cc b/test/cctest/test-log.cc index 5ea283f..6fe3a56 100644 --- a/test/cctest/test-log.cc +++ b/test/cctest/test-log.cc @@ -477,10 +477,9 @@ TEST(EquivalenceOfLoggingAndTraversal) { isolate, log.start(), v8::String::kNormalString, log.length()); initialize_logger.env()->Global()->Set(v8_str("_log"), log_str); - i::Vector source = TestSources::GetScriptsSource(); + i::Vector source = TestSources::GetScriptsSource(); v8::Handle source_str = v8::String::NewFromUtf8( - isolate, reinterpret_cast(source.start()), - v8::String::kNormalString, source.length()); + isolate, source.start(), v8::String::kNormalString, source.length()); v8::TryCatch try_catch; v8::Handle script = CompileWithOrigin(source_str, ""); if (script.IsEmpty()) { diff --git a/tools/js2c.py b/tools/js2c.py index 03da4aa..621ed5a 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -255,8 +255,6 @@ namespace internal { %(sources_declaration)s\ -%(raw_sources_declaration)s\ - template <> int NativesCollection<%(type)s>::GetBuiltinsCount() { return %(builtin_count)i; @@ -274,13 +272,8 @@ namespace internal { } template <> - int NativesCollection<%(type)s>::GetRawScriptsSize() { - return %(raw_total_length)i; - } - - template <> - Vector NativesCollection<%(type)s>::GetRawScriptSource(int index) { -%(get_raw_script_source_cases)s\ + Vector NativesCollection<%(type)s>::GetScriptSource(int index) { +%(get_script_source_cases)s\ return Vector("", 0); } @@ -291,32 +284,15 @@ namespace internal { } template <> - Vector NativesCollection<%(type)s>::GetScriptsSource() { - return Vector(sources, %(total_length)i); + Vector NativesCollection<%(type)s>::GetScriptsSource() { + return Vector(sources, %(total_length)i); } - - template <> - void NativesCollection<%(type)s>::SetRawScriptsSource(Vector raw_source) { - DCHECK(%(raw_total_length)i == raw_source.length()); - raw_sources = raw_source.start(); - } - } // internal } // v8 """ SOURCES_DECLARATION = """\ - static const byte sources[] = { %s }; -""" - - -RAW_SOURCES_COMPRESSION_DECLARATION = """\ - static const char* raw_sources = NULL; -""" - - -RAW_SOURCES_DECLARATION = """\ - static const char* raw_sources = reinterpret_cast(sources); + static const char sources[] = { %s }; """ @@ -325,8 +301,8 @@ GET_INDEX_CASE = """\ """ -GET_RAW_SCRIPT_SOURCE_CASE = """\ - if (index == %(i)i) return Vector(raw_sources + %(offset)i, %(raw_length)i); +GET_SCRIPT_SOURCE_CASE = """\ + if (index == %(i)i) return Vector(sources + %(offset)i, %(source_length)i); """ @@ -440,7 +416,7 @@ def BuildMetadata(sources, source_bytes, native_type): # Loop over modules and build up indices into the source blob: get_index_cases = [] get_script_name_cases = [] - get_raw_script_source_cases = [] + get_script_source_cases = [] offset = 0 for i in xrange(len(sources.modules)): native_name = "native %s.js" % sources.names[i] @@ -450,28 +426,21 @@ def BuildMetadata(sources, source_bytes, native_type): "name": native_name, "length": len(native_name), "offset": offset, - "raw_length": len(sources.modules[i]), + "source_length": len(sources.modules[i]), } get_index_cases.append(GET_INDEX_CASE % d) get_script_name_cases.append(GET_SCRIPT_NAME_CASE % d) - get_raw_script_source_cases.append(GET_RAW_SCRIPT_SOURCE_CASE % d) + get_script_source_cases.append(GET_SCRIPT_SOURCE_CASE % d) offset += len(sources.modules[i]) assert offset == len(raw_sources) - # If we have the raw sources we can declare them accordingly. - have_raw_sources = source_bytes == raw_sources - raw_sources_declaration = (RAW_SOURCES_DECLARATION - if have_raw_sources else RAW_SOURCES_COMPRESSION_DECLARATION) - metadata = { "builtin_count": len(sources.modules), "debugger_count": sum(sources.is_debugger_id), "sources_declaration": SOURCES_DECLARATION % ToCArray(source_bytes), - "raw_sources_declaration": raw_sources_declaration, - "raw_total_length": sum(map(len, sources.modules)), "total_length": total_length, "get_index_cases": "".join(get_index_cases), - "get_raw_script_source_cases": "".join(get_raw_script_source_cases), + "get_script_source_cases": "".join(get_script_source_cases), "get_script_name_cases": "".join(get_script_name_cases), "type": native_type, } -- 2.7.4