3232namespace node {
3333namespace v8_utils {
3434using v8::Array;
35+ using v8::CFunction;
3536using v8::Context;
3637using v8::FunctionCallbackInfo;
3738using v8::FunctionTemplate;
@@ -238,6 +239,23 @@ void SetFlagsFromString(const FunctionCallbackInfo<Value>& args) {
238239 V8::SetFlagsFromString (*flags, static_cast <size_t >(flags.length ()));
239240}
240241
242+ static void IsStringOneByteRepresentation (
243+ const FunctionCallbackInfo<Value>& args) {
244+ CHECK_EQ (args.Length (), 1 );
245+ CHECK (args[0 ]->IsString ());
246+ bool is_one_byte = args[0 ].As <String>()->IsOneByte ();
247+ args.GetReturnValue ().Set (is_one_byte);
248+ }
249+
250+ static bool FastIsStringOneByteRepresentation (Local<Value> receiver,
251+ const Local<Value> target) {
252+ CHECK (target->IsString ());
253+ return target.As <String>()->IsOneByte ();
254+ }
255+
256+ CFunction fast_is_string_one_byte_representation_ (
257+ CFunction::Make (FastIsStringOneByteRepresentation));
258+
241259static const char * GetGCTypeName (v8::GCType gc_type) {
242260 switch (gc_type) {
243261 case v8::GCType::kGCTypeScavenge :
@@ -478,6 +496,13 @@ void Initialize(Local<Object> target,
478496 // Export symbols used by v8.setFlagsFromString()
479497 SetMethod (context, target, " setFlagsFromString" , SetFlagsFromString);
480498
499+ // Export symbols used by v8.isStringOneByteRepresentation()
500+ SetFastMethodNoSideEffect (context,
501+ target,
502+ " isStringOneByteRepresentation" ,
503+ IsStringOneByteRepresentation,
504+ &fast_is_string_one_byte_representation_);
505+
481506 // GCProfiler
482507 Local<FunctionTemplate> t =
483508 NewFunctionTemplate (env->isolate (), GCProfiler::New);
@@ -497,6 +522,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
497522 registry->Register (GCProfiler::New);
498523 registry->Register (GCProfiler::Start);
499524 registry->Register (GCProfiler::Stop);
525+ registry->Register (IsStringOneByteRepresentation);
526+ registry->Register (FastIsStringOneByteRepresentation);
527+ registry->Register (fast_is_string_one_byte_representation_.GetTypeInfo ());
500528}
501529
502530} // namespace v8_utils
0 commit comments