From 23ec442d83b5935fbb8af4d34026d58b7734fe12 Mon Sep 17 00:00:00 2001 From: Philip Lorenz Date: Tue, 11 Sep 2012 17:55:08 +0200 Subject: [PATCH] Always initialise symbol_id for ASCII symbols Commit 30662b5d64ff633f57d89290da2a85507d561187 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 --- src/3rdparty/v8/src/heap-inl.h | 1 + tests/auto/v8/tst_v8.cpp | 6 +++++ tests/auto/v8/v8test.cpp | 48 ++++++++++++++++++++++++++++++++++ tests/auto/v8/v8test.h | 1 + 4 files changed, 56 insertions(+) diff --git a/src/3rdparty/v8/src/heap-inl.h b/src/3rdparty/v8/src/heap-inl.h index d1f66a8..aa933b6 100644 --- a/src/3rdparty/v8/src/heap-inl.h +++ b/src/3rdparty/v8/src/heap-inl.h @@ -127,6 +127,7 @@ MaybeObject* Heap::AllocateAsciiSymbol(Vector 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()); diff --git a/tests/auto/v8/tst_v8.cpp b/tests/auto/v8/tst_v8.cpp index 3983f52..b8ad5d5 100644 --- a/tests/auto/v8/tst_v8.cpp +++ b/tests/auto/v8/tst_v8.cpp @@ -66,6 +66,7 @@ private slots: void fallbackpropertyhandler_callbacks(); void fallbackpropertyhandler_in_prototype(); void fallbackpropertyhandler_nonempty(); + void completehash(); }; void tst_v8::eval() @@ -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); diff --git a/tests/auto/v8/v8test.cpp b/tests/auto/v8/v8test.cpp index 9d59d89..09410a6 100644 --- a/tests/auto/v8/v8test.cpp +++ b/tests/auto/v8/v8test.cpp @@ -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::New(); + Context::Scope context_scope(context); + + Local str; + Local 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(); +} diff --git a/tests/auto/v8/v8test.h b/tests/auto/v8/v8test.h index 0b9a32b..c195b67 100644 --- a/tests/auto/v8/v8test.h +++ b/tests/auto/v8/v8test.h @@ -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