@@ -1055,38 +1055,12 @@ static void EncodeUtf8String(const FunctionCallbackInfo<Value>& args) {
1055
1055
}
1056
1056
1057
1057
1058
- // pass Buffer object to load prototype methods
1059
- void SetupBufferJS (const FunctionCallbackInfo<Value>& args) {
1058
+ void SetBufferPrototype (const FunctionCallbackInfo<Value>& args) {
1060
1059
Environment* env = Environment::GetCurrent (args);
1061
1060
1062
1061
CHECK (args[0 ]->IsObject ());
1063
1062
Local<Object> proto = args[0 ].As <Object>();
1064
1063
env->set_buffer_prototype_object (proto);
1065
-
1066
- env->SetMethodNoSideEffect (proto, " asciiSlice" , StringSlice<ASCII>);
1067
- env->SetMethodNoSideEffect (proto, " base64Slice" , StringSlice<BASE64>);
1068
- env->SetMethodNoSideEffect (proto, " latin1Slice" , StringSlice<LATIN1>);
1069
- env->SetMethodNoSideEffect (proto, " hexSlice" , StringSlice<HEX>);
1070
- env->SetMethodNoSideEffect (proto, " ucs2Slice" , StringSlice<UCS2>);
1071
- env->SetMethodNoSideEffect (proto, " utf8Slice" , StringSlice<UTF8>);
1072
-
1073
- env->SetMethod (proto, " asciiWrite" , StringWrite<ASCII>);
1074
- env->SetMethod (proto, " base64Write" , StringWrite<BASE64>);
1075
- env->SetMethod (proto, " latin1Write" , StringWrite<LATIN1>);
1076
- env->SetMethod (proto, " hexWrite" , StringWrite<HEX>);
1077
- env->SetMethod (proto, " ucs2Write" , StringWrite<UCS2>);
1078
- env->SetMethod (proto, " utf8Write" , StringWrite<UTF8>);
1079
-
1080
- if (auto zero_fill_field = env->isolate_data ()->zero_fill_field ()) {
1081
- CHECK (args[1 ]->IsObject ());
1082
- auto binding_object = args[1 ].As <Object>();
1083
- auto array_buffer = ArrayBuffer::New (env->isolate (),
1084
- zero_fill_field,
1085
- sizeof (*zero_fill_field));
1086
- auto name = FIXED_ONE_BYTE_STRING (env->isolate (), " zeroFill" );
1087
- auto value = Uint32Array::New (array_buffer, 0 , 1 );
1088
- CHECK (binding_object->Set (env->context (), name, value).FromJust ());
1089
- }
1090
1064
}
1091
1065
1092
1066
@@ -1096,7 +1070,7 @@ void Initialize(Local<Object> target,
1096
1070
void * priv) {
1097
1071
Environment* env = Environment::GetCurrent (context);
1098
1072
1099
- env->SetMethod (target, " setupBufferJS " , SetupBufferJS );
1073
+ env->SetMethod (target, " setBufferPrototype " , SetBufferPrototype );
1100
1074
env->SetMethodNoSideEffect (target, " createFromString" , CreateFromString);
1101
1075
1102
1076
env->SetMethodNoSideEffect (target, " byteLengthUtf8" , ByteLengthUtf8);
@@ -1121,6 +1095,32 @@ void Initialize(Local<Object> target,
1121
1095
target->Set (env->context (),
1122
1096
FIXED_ONE_BYTE_STRING (env->isolate (), " kStringMaxLength" ),
1123
1097
Integer::New (env->isolate (), String::kMaxLength )).FromJust ();
1098
+
1099
+ env->SetMethodNoSideEffect (target, " asciiSlice" , StringSlice<ASCII>);
1100
+ env->SetMethodNoSideEffect (target, " base64Slice" , StringSlice<BASE64>);
1101
+ env->SetMethodNoSideEffect (target, " latin1Slice" , StringSlice<LATIN1>);
1102
+ env->SetMethodNoSideEffect (target, " hexSlice" , StringSlice<HEX>);
1103
+ env->SetMethodNoSideEffect (target, " ucs2Slice" , StringSlice<UCS2>);
1104
+ env->SetMethodNoSideEffect (target, " utf8Slice" , StringSlice<UTF8>);
1105
+
1106
+ env->SetMethod (target, " asciiWrite" , StringWrite<ASCII>);
1107
+ env->SetMethod (target, " base64Write" , StringWrite<BASE64>);
1108
+ env->SetMethod (target, " latin1Write" , StringWrite<LATIN1>);
1109
+ env->SetMethod (target, " hexWrite" , StringWrite<HEX>);
1110
+ env->SetMethod (target, " ucs2Write" , StringWrite<UCS2>);
1111
+ env->SetMethod (target, " utf8Write" , StringWrite<UTF8>);
1112
+
1113
+ // It can be a nullptr when running inside an isolate where we
1114
+ // do not own the ArrayBuffer allocator.
1115
+ if (uint32_t * zero_fill_field = env->isolate_data ()->zero_fill_field ()) {
1116
+ Local<ArrayBuffer> array_buffer = ArrayBuffer::New (
1117
+ env->isolate (), zero_fill_field, sizeof (*zero_fill_field));
1118
+ CHECK (target
1119
+ ->Set (env->context (),
1120
+ FIXED_ONE_BYTE_STRING (env->isolate (), " zeroFill" ),
1121
+ Uint32Array::New (array_buffer, 0 , 1 ))
1122
+ .FromJust ());
1123
+ }
1124
1124
}
1125
1125
1126
1126
} // anonymous namespace
0 commit comments