@@ -1153,14 +1153,26 @@ Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate,
11531153 v8::Local<Value> data,
11541154 v8::Local<Signature> signature,
11551155 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) {
11561166 i::Isolate* i_isolate = reinterpret_cast <i::Isolate*>(isolate);
11571167 // Changes to the environment cannot be captured in the snapshot. Expect no
11581168 // function templates when the isolate is created for serialization.
11591169 DCHECK (!i_isolate->serializer_enabled ());
11601170 LOG_API (i_isolate, " FunctionTemplate::New" );
11611171 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;
11641176}
11651177
11661178
@@ -4449,15 +4461,21 @@ Local<v8::Value> Object::CallAsConstructor(int argc,
44494461MaybeLocal<Function> Function::New (Local<Context> context,
44504462 FunctionCallback callback, Local<Value> data,
44514463 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) {
44524470 i::Isolate* isolate = Utils::OpenHandle (*context)->GetIsolate ();
44534471 LOG_API (isolate, " Function::New" );
44544472 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);
44584477}
44594478
4460-
44614479Local<Function> Function::New (Isolate* v8_isolate, FunctionCallback callback,
44624480 Local<Value> data, int length) {
44634481 return Function::New (v8_isolate->GetCurrentContext (), callback, data, length)
0 commit comments