Skip to content

Commit

Permalink
Always initialise symbol_id for ASCII symbols
Browse files Browse the repository at this point in the history
Commit 30662b5 dropped the default
initialisation of the symbol_id for ASCII characters. This leads to
problems when trying to access the symbol_id when the symbol was not
instantiated via AsciiSymbolKey (e.g. via SubStringAsciiSymbolKey).

Additionally, AsciiSymbolKey does not guarantee the presence of a
symbol_id in case the SMI value space has been exhausted.

Change-Id: I778bc5cc3cee80038a4ca6606bfcf4423d569132
Reviewed-by: Peter Varga <[email protected]>
  • Loading branch information
lorenzph authored and The Qt Project committed Sep 24, 2012
1 parent a7cbe37 commit 23ec442
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/3rdparty/v8/src/heap-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ MaybeObject* Heap::AllocateAsciiSymbol(Vector<const char> str,
String* answer = String::cast(result);
answer->set_length(str.length());
answer->set_hash_field(hash_field);
SeqString::cast(answer)->set_symbol_id(0);

ASSERT_EQ(size, answer->Size());

Expand Down
6 changes: 6 additions & 0 deletions tests/auto/v8/tst_v8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private slots:
void fallbackpropertyhandler_callbacks();
void fallbackpropertyhandler_in_prototype();
void fallbackpropertyhandler_nonempty();
void completehash();
};

void tst_v8::eval()
Expand Down Expand Up @@ -128,6 +129,11 @@ void tst_v8::fallbackpropertyhandler_nonempty()
QVERIFY(v8test_fallbackpropertyhandler_nonempty());
}

void tst_v8::completehash()
{
QVERIFY(v8test_completehash());
}

int main(int argc, char *argv[])
{
V8::SetFlagsFromCommandLine(&argc, argv, true);
Expand Down
48 changes: 48 additions & 0 deletions tests/auto/v8/v8test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,3 +1041,51 @@ bool v8test_fallbackpropertyhandler_nonempty()

ENDTEST();
}

bool v8test_completehash()
{
#define HASH_EQUALS(str1, str2) \
{ \
String::CompleteHashData hash1 = str1->CompleteHash(); \
String::CompleteHashData hash2 = str2->CompleteHash(); \
VERIFY(hash1.length == hash2.length); \
VERIFY(hash1.symbol_id == hash2.symbol_id || (hash1.symbol_id == 0 || hash2.symbol_id == 0)); \
VERIFY(hash1.hash == hash2.hash); \
};

BEGINTEST();

HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);

Local<String> str;
Local<String> str2;
uint16_t input[] = { 'I', 'n', 'p', 'u', 't', 0 };

str = String::New("Input");
str2 = String::New("Input");
HASH_EQUALS(str, str2);

str = String::New(input);
str2 = String::New(input);
HASH_EQUALS(str, str2);

str = String::NewSymbol("input");
str2 = String::NewSymbol("input");
HASH_EQUALS(str, str2);

str = CompileRun("var input = \"{ \\\"abc\\\": \\\"value\\\" }\"; input")->ToString();
str2 = CompileRun("var input2 = \"{ \\\"abc\\\": \\\"value\\\" }\"; input2")->ToString();
HASH_EQUALS(str, str2);

// SubStringAsciiSymbolKey is created via the built-in JSON parser for
// property names.
str = CompileRun("JSON.parse(input)")->ToObject()->GetOwnPropertyNames()->Get(0)->ToString();
str2 = CompileRun("JSON.parse(input2)")->ToObject()->GetOwnPropertyNames()->Get(0)->ToString();
HASH_EQUALS(str, str2);
cleanup:
context.Dispose();

ENDTEST();
}
1 change: 1 addition & 0 deletions tests/auto/v8/v8test.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ bool v8test_qtbug_24871();
bool v8test_fallbackpropertyhandler_callbacks();
bool v8test_fallbackpropertyhandler_in_prototype();
bool v8test_fallbackpropertyhandler_nonempty();
bool v8test_completehash();

#endif // V8TEST_H

0 comments on commit 23ec442

Please sign in to comment.