From 881a921bb2f1d0dfba6b45f460d1a07243ea414e Mon Sep 17 00:00:00 2001 From: vogelheim Date: Tue, 2 Dec 2014 10:53:27 -0800 Subject: [PATCH] Fix NativesCollection<.>::GetScriptName in natives-external.cc As there's no associated bug, here's the issue: - Some ES6 functionality in Chrome is presently broken; this fixes it. - The natives (built-in libraries) can be accessed by their 'name'. This is used to active ES6 flags. - Strangely enough, there's an id and a name, where the name is derived from the id as "native %s.js", with %s for the id. - NativesCollection<.>::GetScriptName uses the name. - NativesCollection<.>::GetIndex uses the id. - Example: NativesCollection::GetIndex("harmony-string") -> 3 NativesCollection::GetScriptName(3) -> "native harmony-string.js" - Nobody knows why; it's quite mysterious. - When introducing the "external startup data", I didn't fully understand this and used the id in both places. - When the "external startup data" was turned on in Chrome, ES6 features broke in Chrome since the libraries could no longer be found. - This CL fixes this and makes the external startup data behave just like the built-in version. R=dslomov BUG= Review URL: https://codereview.chromium.org/774613003 Cr-Commit-Position: refs/heads/master@{#25624} --- src/bootstrapper.cc | 25 +++++++++---------------- src/natives-external.cc | 43 ++++++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index 052d9f6..53733ff 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -2151,14 +2151,6 @@ bool Genesis::InstallNatives() { } -#define INSTALL_EXPERIMENTAL_NATIVE(i, flag, file) \ - if (FLAG_##flag && \ - strcmp(ExperimentalNatives::GetScriptName(i).start(), "native " file) == \ - 0) { \ - if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ - } - - bool Genesis::InstallExperimentalNatives() { static const char* harmony_arrays_natives[] = { "native harmony-array.js", "native harmony-typedarray.js", NULL}; @@ -2182,14 +2174,15 @@ bool Genesis::InstallExperimentalNatives() { for (int i = ExperimentalNatives::GetDebuggerCount(); i < ExperimentalNatives::GetBuiltinsCount(); i++) { -#define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ - if (FLAG_##id) { \ - for (size_t j = 0; id##_natives[j] != NULL; j++) { \ - if (strcmp(ExperimentalNatives::GetScriptName(i).start(), \ - id##_natives[j]) == 0) { \ - if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ - } \ - } \ +#define INSTALL_EXPERIMENTAL_NATIVES(id, desc) \ + if (FLAG_##id) { \ + for (size_t j = 0; id##_natives[j] != NULL; j++) { \ + Vector script_name = ExperimentalNatives::GetScriptName(i); \ + if (strncmp(script_name.start(), id##_natives[j], \ + script_name.length()) == 0) { \ + if (!CompileExperimentalBuiltin(isolate(), i)) return false; \ + } \ + } \ } HARMONY_INPROGRESS(INSTALL_EXPERIMENTAL_NATIVES); HARMONY_STAGED(INSTALL_EXPERIMENTAL_NATIVES); diff --git a/src/natives-external.cc b/src/natives-external.cc index 4e9111c..75e866b 100644 --- a/src/natives-external.cc +++ b/src/natives-external.cc @@ -23,20 +23,26 @@ namespace internal { */ class NativesStore { public: - ~NativesStore() {} + ~NativesStore() { + for (int i = 0; i < native_names_.length(); i++) { + native_names_[i].Dispose(); + } + } - int GetBuiltinsCount() { return native_names_.length(); } + int GetBuiltinsCount() { return native_ids_.length(); } int GetDebuggerCount() { return debugger_count_; } + Vector GetScriptName(int index) { return native_names_[index]; } + Vector GetRawScriptSource(int index) { return native_source_[index]; } - int GetIndex(const char* name) { - for (int i = 0; i < native_names_.length(); ++i) { - int native_name_length = native_names_[i].length(); - if ((static_cast(strlen(name)) == native_name_length) && - (strncmp(name, native_names_[i].start(), native_name_length) == 0)) { + int GetIndex(const char* id) { + for (int i = 0; i < native_ids_.length(); ++i) { + int native_id_length = native_ids_[i].length(); + if ((static_cast(strlen(id)) == native_id_length) && + (strncmp(id, native_ids_[i].start(), native_id_length) == 0)) { return i; } } @@ -75,24 +81,35 @@ class NativesStore { private: NativesStore() : debugger_count_(0) {} + Vector NameFromId(const byte* id, int id_length) { + Vector name(Vector::New(id_length + 11)); + SimpleStringBuilder builder(name.start(), name.length()); + builder.AddString("native "); + builder.AddSubstring(reinterpret_cast(id), id_length); + builder.AddString(".js"); + return Vector::cast(name); + } + bool ReadNameAndContentPair(SnapshotByteSource* bytes) { - const byte* name; - int name_length; + const byte* id; + int id_length; const byte* source; int source_length; - bool success = bytes->GetBlob(&name, &name_length) && + bool success = bytes->GetBlob(&id, &id_length) && bytes->GetBlob(&source, &source_length); if (success) { - Vector name_vector( - reinterpret_cast(name), name_length); + Vector id_vector(reinterpret_cast(id), + id_length); Vector source_vector( reinterpret_cast(source), source_length); - native_names_.Add(name_vector); + native_ids_.Add(id_vector); native_source_.Add(source_vector); + native_names_.Add(NameFromId(id, id_length)); } return success; } + List > native_ids_; List > native_names_; List > native_source_; int debugger_count_; -- 2.7.4