Skip to content

Commit 7da23dc

Browse files
addaleaxcodebytere
authored andcommitted
deps: V8: backport 61f4c22
The differences to the original patch are the replacement of `i::IsIdentifier...()` with `unicode_cache_.IsIdentifier...()`, because the former is not available on Node.js v11.x, as well as the omitted `no_gc` argument for `GetFlatContent()`. Original commit message: Assume flat string when checking CompileFunctionInContext arguments. R=jkummerow@chromium.org Change-Id: I54c6137a3c6e14d4102188f154aa7216e7414dbc Reviewed-on: https://chromium-review.googlesource.com/c/1388533 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Commit-Queue: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#58562} Refs: v8/v8@61f4c22 Fixes: #27256 PR-URL: #27259 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com>
1 parent bf2c283 commit 7da23dc

File tree

3 files changed

+32
-47
lines changed

3 files changed

+32
-47
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# Reset this number to 0 on major V8 upgrades.
3232
# Increment by one for each non-official patch applied to deps/v8.
33-
'v8_embedder_string': '-node.18',
33+
'v8_embedder_string': '-node.19',
3434

3535
# Turn on SipHash for hash seed generation, addresses HashWick
3636
'v8_use_siphash': 'true',

deps/v8/src/api.cc

+21-37
Original file line numberDiff line numberDiff line change
@@ -2424,44 +2424,29 @@ MaybeLocal<Module> ScriptCompiler::CompileModule(
24242424
return ToApiHandle<Module>(i_isolate->factory()->NewModule(shared));
24252425
}
24262426

2427-
2428-
class IsIdentifierHelper {
2429-
public:
2430-
IsIdentifierHelper() : is_identifier_(false), first_char_(true) {}
2431-
2432-
bool Check(i::String* string) {
2433-
i::ConsString* cons_string = i::String::VisitFlat(this, string, 0);
2434-
if (cons_string == nullptr) return is_identifier_;
2435-
// We don't support cons strings here.
2436-
return false;
2437-
}
2438-
void VisitOneByteString(const uint8_t* chars, int length) {
2439-
for (int i = 0; i < length; ++i) {
2440-
if (first_char_) {
2441-
first_char_ = false;
2442-
is_identifier_ = unicode_cache_.IsIdentifierStart(chars[0]);
2443-
} else {
2444-
is_identifier_ &= unicode_cache_.IsIdentifierPart(chars[i]);
2445-
}
2427+
namespace {
2428+
bool IsIdentifier(i::Isolate* isolate, i::Handle<i::String> string) {
2429+
i::UnicodeCache unicode_cache_;
2430+
string = i::String::Flatten(isolate, string);
2431+
const int length = string->length();
2432+
if (length == 0) return false;
2433+
if (!unicode_cache_.IsIdentifierStart(string->Get(0))) return false;
2434+
i::DisallowHeapAllocation no_gc;
2435+
i::String::FlatContent flat = string->GetFlatContent();
2436+
if (flat.IsOneByte()) {
2437+
auto vector = flat.ToOneByteVector();
2438+
for (int i = 1; i < length; i++) {
2439+
if (!unicode_cache_.IsIdentifierPart(vector[i])) return false;
24462440
}
2447-
}
2448-
void VisitTwoByteString(const uint16_t* chars, int length) {
2449-
for (int i = 0; i < length; ++i) {
2450-
if (first_char_) {
2451-
first_char_ = false;
2452-
is_identifier_ = unicode_cache_.IsIdentifierStart(chars[0]);
2453-
} else {
2454-
is_identifier_ &= unicode_cache_.IsIdentifierPart(chars[i]);
2455-
}
2441+
} else {
2442+
auto vector = flat.ToUC16Vector();
2443+
for (int i = 1; i < length; i++) {
2444+
if (!unicode_cache_.IsIdentifierPart(vector[i])) return false;
24562445
}
24572446
}
2458-
2459-
private:
2460-
bool is_identifier_;
2461-
bool first_char_;
2462-
i::UnicodeCache unicode_cache_;
2463-
DISALLOW_COPY_AND_ASSIGN(IsIdentifierHelper);
2464-
};
2447+
return true;
2448+
}
2449+
} // anonymous namespace
24652450

24662451
MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
24672452
Local<Context> v8_context, Source* source, size_t arguments_count,
@@ -2486,9 +2471,8 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
24862471
i::Handle<i::FixedArray> arguments_list =
24872472
isolate->factory()->NewFixedArray(static_cast<int>(arguments_count));
24882473
for (int i = 0; i < static_cast<int>(arguments_count); i++) {
2489-
IsIdentifierHelper helper;
24902474
i::Handle<i::String> argument = Utils::OpenHandle(*arguments[i]);
2491-
if (!helper.Check(*argument)) return Local<Function>();
2475+
if (!IsIdentifier(isolate, argument)) return Local<Function>();
24922476
arguments_list->set(i, *argument);
24932477
}
24942478

deps/v8/test/cctest/test-compiler.cc

+10-9
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ TEST(CompileFunctionInContextArgs) {
487487
v8::Local<v8::Object> ext[1];
488488
ext[0] = v8::Local<v8::Object>::Cast(
489489
env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked());
490-
v8::ScriptCompiler::Source script_source(v8_str("result = x + b"));
491-
v8::Local<v8::String> arg = v8_str("b");
490+
v8::ScriptCompiler::Source script_source(v8_str("result = x + abc"));
491+
v8::Local<v8::String> arg = v8_str("abc");
492492
v8::Local<v8::Function> fun =
493493
v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source,
494494
1, &arg, 1, ext)
@@ -498,8 +498,8 @@ TEST(CompileFunctionInContextArgs) {
498498
->ToInt32(env.local())
499499
.ToLocalChecked()
500500
->Value());
501-
v8::Local<v8::Value> b_value = v8::Number::New(CcTest::isolate(), 42.0);
502-
fun->Call(env.local(), env->Global(), 1, &b_value).ToLocalChecked();
501+
v8::Local<v8::Value> arg_value = v8::Number::New(CcTest::isolate(), 42.0);
502+
fun->Call(env.local(), env->Global(), 1, &arg_value).ToLocalChecked();
503503
CHECK(env->Global()->Has(env.local(), v8_str("result")).FromJust());
504504
v8::Local<v8::Value> result =
505505
env->Global()->Get(env.local(), v8_str("result")).ToLocalChecked();
@@ -516,16 +516,17 @@ TEST(CompileFunctionInContextComments) {
516516
v8::Local<v8::Object> ext[1];
517517
ext[0] = v8::Local<v8::Object>::Cast(
518518
env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked());
519-
v8::ScriptCompiler::Source script_source(
520-
v8_str("result = /* y + */ x + b // + z"));
521-
v8::Local<v8::String> arg = v8_str("b");
519+
v8::Local<v8::String> source =
520+
CompileRun("'result = /* y + */ x + a\\u4e00 // + z'").As<v8::String>();
521+
v8::ScriptCompiler::Source script_source(source);
522+
v8::Local<v8::String> arg = CompileRun("'a\\u4e00'").As<v8::String>();
522523
v8::Local<v8::Function> fun =
523524
v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source,
524525
1, &arg, 1, ext)
525526
.ToLocalChecked();
526527
CHECK(!fun.IsEmpty());
527-
v8::Local<v8::Value> b_value = v8::Number::New(CcTest::isolate(), 42.0);
528-
fun->Call(env.local(), env->Global(), 1, &b_value).ToLocalChecked();
528+
v8::Local<v8::Value> arg_value = v8::Number::New(CcTest::isolate(), 42.0);
529+
fun->Call(env.local(), env->Global(), 1, &arg_value).ToLocalChecked();
529530
CHECK(env->Global()->Has(env.local(), v8_str("result")).FromJust());
530531
v8::Local<v8::Value> result =
531532
env->Global()->Get(env.local(), v8_str("result")).ToLocalChecked();

0 commit comments

Comments
 (0)