diff --git a/common.gypi b/common.gypi index 338ed2cbbb9bb8..f405156a20b26c 100644 --- a/common.gypi +++ b/common.gypi @@ -30,7 +30,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.18', + 'v8_embedder_string': '-node.19', # Turn on SipHash for hash seed generation, addresses HashWick 'v8_use_siphash': 'true', diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index 3f0cad545f5cee..372387e0c9ef51 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -2424,44 +2424,29 @@ MaybeLocal ScriptCompiler::CompileModule( return ToApiHandle(i_isolate->factory()->NewModule(shared)); } - -class IsIdentifierHelper { - public: - IsIdentifierHelper() : is_identifier_(false), first_char_(true) {} - - bool Check(i::String* string) { - i::ConsString* cons_string = i::String::VisitFlat(this, string, 0); - if (cons_string == nullptr) return is_identifier_; - // We don't support cons strings here. - return false; - } - void VisitOneByteString(const uint8_t* chars, int length) { - for (int i = 0; i < length; ++i) { - if (first_char_) { - first_char_ = false; - is_identifier_ = unicode_cache_.IsIdentifierStart(chars[0]); - } else { - is_identifier_ &= unicode_cache_.IsIdentifierPart(chars[i]); - } +namespace { +bool IsIdentifier(i::Isolate* isolate, i::Handle string) { + i::UnicodeCache unicode_cache_; + string = i::String::Flatten(isolate, string); + const int length = string->length(); + if (length == 0) return false; + if (!unicode_cache_.IsIdentifierStart(string->Get(0))) return false; + i::DisallowHeapAllocation no_gc; + i::String::FlatContent flat = string->GetFlatContent(); + if (flat.IsOneByte()) { + auto vector = flat.ToOneByteVector(); + for (int i = 1; i < length; i++) { + if (!unicode_cache_.IsIdentifierPart(vector[i])) return false; } - } - void VisitTwoByteString(const uint16_t* chars, int length) { - for (int i = 0; i < length; ++i) { - if (first_char_) { - first_char_ = false; - is_identifier_ = unicode_cache_.IsIdentifierStart(chars[0]); - } else { - is_identifier_ &= unicode_cache_.IsIdentifierPart(chars[i]); - } + } else { + auto vector = flat.ToUC16Vector(); + for (int i = 1; i < length; i++) { + if (!unicode_cache_.IsIdentifierPart(vector[i])) return false; } } - - private: - bool is_identifier_; - bool first_char_; - i::UnicodeCache unicode_cache_; - DISALLOW_COPY_AND_ASSIGN(IsIdentifierHelper); -}; + return true; +} +} // anonymous namespace MaybeLocal ScriptCompiler::CompileFunctionInContext( Local v8_context, Source* source, size_t arguments_count, @@ -2486,9 +2471,8 @@ MaybeLocal ScriptCompiler::CompileFunctionInContext( i::Handle arguments_list = isolate->factory()->NewFixedArray(static_cast(arguments_count)); for (int i = 0; i < static_cast(arguments_count); i++) { - IsIdentifierHelper helper; i::Handle argument = Utils::OpenHandle(*arguments[i]); - if (!helper.Check(*argument)) return Local(); + if (!IsIdentifier(isolate, argument)) return Local(); arguments_list->set(i, *argument); } diff --git a/deps/v8/test/cctest/test-compiler.cc b/deps/v8/test/cctest/test-compiler.cc index 63904e086f7de3..0263d20c4891b0 100644 --- a/deps/v8/test/cctest/test-compiler.cc +++ b/deps/v8/test/cctest/test-compiler.cc @@ -487,8 +487,8 @@ TEST(CompileFunctionInContextArgs) { v8::Local ext[1]; ext[0] = v8::Local::Cast( env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked()); - v8::ScriptCompiler::Source script_source(v8_str("result = x + b")); - v8::Local arg = v8_str("b"); + v8::ScriptCompiler::Source script_source(v8_str("result = x + abc")); + v8::Local arg = v8_str("abc"); v8::Local fun = v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source, 1, &arg, 1, ext) @@ -498,8 +498,8 @@ TEST(CompileFunctionInContextArgs) { ->ToInt32(env.local()) .ToLocalChecked() ->Value()); - v8::Local b_value = v8::Number::New(CcTest::isolate(), 42.0); - fun->Call(env.local(), env->Global(), 1, &b_value).ToLocalChecked(); + v8::Local arg_value = v8::Number::New(CcTest::isolate(), 42.0); + fun->Call(env.local(), env->Global(), 1, &arg_value).ToLocalChecked(); CHECK(env->Global()->Has(env.local(), v8_str("result")).FromJust()); v8::Local result = env->Global()->Get(env.local(), v8_str("result")).ToLocalChecked(); @@ -516,16 +516,17 @@ TEST(CompileFunctionInContextComments) { v8::Local ext[1]; ext[0] = v8::Local::Cast( env->Global()->Get(env.local(), v8_str("a")).ToLocalChecked()); - v8::ScriptCompiler::Source script_source( - v8_str("result = /* y + */ x + b // + z")); - v8::Local arg = v8_str("b"); + v8::Local source = + CompileRun("'result = /* y + */ x + a\\u4e00 // + z'").As(); + v8::ScriptCompiler::Source script_source(source); + v8::Local arg = CompileRun("'a\\u4e00'").As(); v8::Local fun = v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source, 1, &arg, 1, ext) .ToLocalChecked(); CHECK(!fun.IsEmpty()); - v8::Local b_value = v8::Number::New(CcTest::isolate(), 42.0); - fun->Call(env.local(), env->Global(), 1, &b_value).ToLocalChecked(); + v8::Local arg_value = v8::Number::New(CcTest::isolate(), 42.0); + fun->Call(env.local(), env->Global(), 1, &arg_value).ToLocalChecked(); CHECK(env->Global()->Has(env.local(), v8_str("result")).FromJust()); v8::Local result = env->Global()->Get(env.local(), v8_str("result")).ToLocalChecked();