@@ -1153,14 +1153,26 @@ Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate,
1153
1153
v8::Local<Value> data,
1154
1154
v8::Local<Signature> signature,
1155
1155
int length) {
1156
+ return New (
1157
+ isolate, callback, data, signature, length, ConstructorBehavior::kAllow );
1158
+ }
1159
+
1160
+ Local<FunctionTemplate> FunctionTemplate::New (Isolate* isolate,
1161
+ FunctionCallback callback,
1162
+ v8::Local<Value> data,
1163
+ v8::Local<Signature> signature,
1164
+ int length,
1165
+ ConstructorBehavior behavior) {
1156
1166
i::Isolate* i_isolate = reinterpret_cast <i::Isolate*>(isolate);
1157
1167
// Changes to the environment cannot be captured in the snapshot. Expect no
1158
1168
// function templates when the isolate is created for serialization.
1159
1169
DCHECK (!i_isolate->serializer_enabled ());
1160
1170
LOG_API (i_isolate, " FunctionTemplate::New" );
1161
1171
ENTER_V8 (i_isolate);
1162
- return FunctionTemplateNew (i_isolate, callback, nullptr , data, signature,
1163
- length, false );
1172
+ auto tmpl = FunctionTemplateNew (i_isolate, callback, nullptr , data, signature,
1173
+ length, false );
1174
+ if (behavior == ConstructorBehavior::kThrow ) tmpl->RemovePrototype ();
1175
+ return tmpl;
1164
1176
}
1165
1177
1166
1178
@@ -4449,15 +4461,21 @@ Local<v8::Value> Object::CallAsConstructor(int argc,
4449
4461
MaybeLocal<Function> Function::New (Local<Context> context,
4450
4462
FunctionCallback callback, Local<Value> data,
4451
4463
int length) {
4464
+ return New (context, callback, data, length, ConstructorBehavior::kAllow );
4465
+ }
4466
+
4467
+ MaybeLocal<Function> Function::New (Local<Context> context,
4468
+ FunctionCallback callback, Local<Value> data,
4469
+ int length, ConstructorBehavior behavior) {
4452
4470
i::Isolate* isolate = Utils::OpenHandle (*context)->GetIsolate ();
4453
4471
LOG_API (isolate, " Function::New" );
4454
4472
ENTER_V8 (isolate);
4455
- return FunctionTemplateNew (isolate, callback, nullptr , data,
4456
- Local<Signature>(), length, true )
4457
- ->GetFunction (context);
4473
+ auto tmpl = FunctionTemplateNew (isolate, callback, nullptr , data,
4474
+ Local<Signature>(), length, true );
4475
+ if (behavior == ConstructorBehavior::kThrow ) tmpl->RemovePrototype ();
4476
+ return tmpl->GetFunction (context);
4458
4477
}
4459
4478
4460
-
4461
4479
Local<Function> Function::New (Isolate* v8_isolate, FunctionCallback callback,
4462
4480
Local<Value> data, int length) {
4463
4481
return Function::New (v8_isolate->GetCurrentContext (), callback, data, length)
0 commit comments