Skip to content

Commit b4c51c5

Browse files
vkurchatkinofrobots
authored andcommitted
deps: backport 200315c from V8 upstream
Original commit message: Make AstRawString deduplication encoding-agnostic. [email protected] BUG=v8:4450 LOG=N Review URL: https://codereview.chromium.org/1411103006 Cr-Commit-Position: refs/heads/master@{#31624} Ref: #4160 PR-URL: #4128 Reviewed-By: jasnell - James M Snell <[email protected]> Reviewed-By: targos - Michaël Zasso <[email protected]> Reviewed-By: indutny - Fedor Indutny <[email protected]>
1 parent 17fc5b4 commit b4c51c5

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

deps/v8/src/ast-value-factory.cc

+26-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "src/api.h"
3131
#include "src/objects.h"
32+
#include "src/utils.h"
3233

3334
namespace v8 {
3435
namespace internal {
@@ -379,11 +380,32 @@ AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte,
379380
bool AstValueFactory::AstRawStringCompare(void* a, void* b) {
380381
const AstRawString* lhs = static_cast<AstRawString*>(a);
381382
const AstRawString* rhs = static_cast<AstRawString*>(b);
382-
if (lhs->is_one_byte() != rhs->is_one_byte()) return false;
383+
if (lhs->length() != rhs->length()) return false;
383384
if (lhs->hash() != rhs->hash()) return false;
384-
int len = lhs->byte_length();
385-
if (rhs->byte_length() != len) return false;
386-
return memcmp(lhs->raw_data(), rhs->raw_data(), len) == 0;
385+
const unsigned char* l = lhs->raw_data();
386+
const unsigned char* r = rhs->raw_data();
387+
size_t length = rhs->length();
388+
if (lhs->is_one_byte()) {
389+
if (rhs->is_one_byte()) {
390+
return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l),
391+
reinterpret_cast<const uint8_t*>(r),
392+
length) == 0;
393+
} else {
394+
return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(l),
395+
reinterpret_cast<const uint16_t*>(r),
396+
length) == 0;
397+
}
398+
} else {
399+
if (rhs->is_one_byte()) {
400+
return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
401+
reinterpret_cast<const uint8_t*>(r),
402+
length) == 0;
403+
} else {
404+
return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l),
405+
reinterpret_cast<const uint16_t*>(r),
406+
length) == 0;
407+
}
408+
}
387409
}
388410
} // namespace internal
389411
} // namespace v8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2015 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
({})['foobar\u2653'.slice(0, 6)] = null;
6+
var x;
7+
eval('x = function foobar() { return foobar };');
8+
x();

0 commit comments

Comments
 (0)