From c3a9d8a62e605e494a9542ef28b6ddf16e8ec49f Mon Sep 17 00:00:00 2001 From: Vladimir Kurchatkin Date: Thu, 3 Dec 2015 15:34:52 +0300 Subject: [PATCH] deps: backport 200315c from V8 upstream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: Make AstRawString deduplication encoding-agnostic. R=jkummerow@chromium.org BUG=v8:4450 LOG=N Review URL: https://codereview.chromium.org/1411103006 Cr-Commit-Position: refs/heads/master@{#31624} Ref: https://github.com/nodejs/node/pull/4160 PR-URL: https://github.com/nodejs/node/pull/4128 Reviewed-By: jasnell - James M Snell Reviewed-By: targos - Michaƫl Zasso Reviewed-By: indutny - Fedor Indutny --- deps/v8/src/ast-value-factory.cc | 30 +++++++++++++++++--- deps/v8/test/mjsunit/regress/regress-4450.js | 8 ++++++ 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 deps/v8/test/mjsunit/regress/regress-4450.js diff --git a/deps/v8/src/ast-value-factory.cc b/deps/v8/src/ast-value-factory.cc index 68cf015200365c..fbcde8b45703fc 100644 --- a/deps/v8/src/ast-value-factory.cc +++ b/deps/v8/src/ast-value-factory.cc @@ -29,6 +29,7 @@ #include "src/api.h" #include "src/objects.h" +#include "src/utils.h" namespace v8 { namespace internal { @@ -379,11 +380,32 @@ AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte, bool AstValueFactory::AstRawStringCompare(void* a, void* b) { const AstRawString* lhs = static_cast(a); const AstRawString* rhs = static_cast(b); - if (lhs->is_one_byte() != rhs->is_one_byte()) return false; + if (lhs->length() != rhs->length()) return false; if (lhs->hash() != rhs->hash()) return false; - int len = lhs->byte_length(); - if (rhs->byte_length() != len) return false; - return memcmp(lhs->raw_data(), rhs->raw_data(), len) == 0; + const unsigned char* l = lhs->raw_data(); + const unsigned char* r = rhs->raw_data(); + size_t length = rhs->length(); + if (lhs->is_one_byte()) { + if (rhs->is_one_byte()) { + return CompareCharsUnsigned(reinterpret_cast(l), + reinterpret_cast(r), + length) == 0; + } else { + return CompareCharsUnsigned(reinterpret_cast(l), + reinterpret_cast(r), + length) == 0; + } + } else { + if (rhs->is_one_byte()) { + return CompareCharsUnsigned(reinterpret_cast(l), + reinterpret_cast(r), + length) == 0; + } else { + return CompareCharsUnsigned(reinterpret_cast(l), + reinterpret_cast(r), + length) == 0; + } + } } } // namespace internal } // namespace v8 diff --git a/deps/v8/test/mjsunit/regress/regress-4450.js b/deps/v8/test/mjsunit/regress/regress-4450.js new file mode 100644 index 00000000000000..31ff4f19c26d77 --- /dev/null +++ b/deps/v8/test/mjsunit/regress/regress-4450.js @@ -0,0 +1,8 @@ +// Copyright 2015 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +({})['foobar\u2653'.slice(0, 6)] = null; +var x; +eval('x = function foobar() { return foobar };'); +x();