Reviewers: dslomov_gmail.com,
Description:
Fix NativesCollection<.>::GetScriptName in natives-external.cc
As there's no associate 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<EXPERIMENTAL>::GetIndex("harmony-string") -> 3
NativesCollection<EXPERIMENTAL>::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=
Please review this at https://codereview.chromium.org/774613003/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+30, -13 lines):
M src/natives-external.cc
Index: src/natives-external.cc
diff --git a/src/natives-external.cc b/src/natives-external.cc
index
fc6614949c6daf68d175504949c648b462f8953d..75f0ac806e5de95cde02f11ec0c8c0d8128f3f8f
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<const char> GetScriptName(int index) { return
native_names_[index]; }
+
Vector<const char> 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<int>(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<int>(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<const char> NameFromId(const byte* id, int id_length) {
+ Vector<char> name(Vector<char>::New(id_length + 11));
+ SimpleStringBuilder builder(name.start(), name.length());
+ builder.AddString("native ");
+ builder.AddSubstring(reinterpret_cast<const char*>(id), id_length);
+ builder.AddString(".js");
+ return Vector<const char>::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<const char> name_vector(
- reinterpret_cast<const char*>(name), name_length);
+ Vector<const char> id_vector(reinterpret_cast<const char*>(id),
+ id_length);
Vector<const char> source_vector(
reinterpret_cast<const char*>(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<Vector<const char> > native_ids_;
List<Vector<const char> > native_names_;
List<Vector<const char> > native_source_;
int debugger_count_;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.