@@ -681,17 +681,41 @@ inline void Environment::ThrowUVException(int errorno,
681
681
inline v8::Local<v8::FunctionTemplate>
682
682
Environment::NewFunctionTemplate (v8::FunctionCallback callback,
683
683
v8::Local<v8::Signature> signature,
684
- v8::ConstructorBehavior behavior) {
684
+ v8::ConstructorBehavior behavior,
685
+ v8::SideEffectType side_effect_type) {
685
686
v8::Local<v8::External> external = as_external ();
686
687
return v8::FunctionTemplate::New (isolate (), callback, external,
687
- signature, 0 , behavior);
688
+ signature, 0 , behavior, side_effect_type );
688
689
}
689
690
690
691
inline void Environment::SetMethod (v8::Local<v8::Object> that,
691
692
const char * name,
692
693
v8::FunctionCallback callback) {
693
694
v8::Local<v8::Function> function =
694
- NewFunctionTemplate (callback)->GetFunction ();
695
+ NewFunctionTemplate (callback,
696
+ v8::Local<v8::Signature>(),
697
+ // TODO(TimothyGu): Investigate if SetMethod is ever
698
+ // used for constructors.
699
+ v8::ConstructorBehavior::kAllow ,
700
+ v8::SideEffectType::kHasSideEffect )->GetFunction ();
701
+ // kInternalized strings are created in the old space.
702
+ const v8::NewStringType type = v8::NewStringType::kInternalized ;
703
+ v8::Local<v8::String> name_string =
704
+ v8::String::NewFromUtf8 (isolate (), name, type).ToLocalChecked ();
705
+ that->Set (name_string, function);
706
+ function->SetName (name_string); // NODE_SET_METHOD() compatibility.
707
+ }
708
+
709
+ inline void Environment::SetMethodNoSideEffect (v8::Local<v8::Object> that,
710
+ const char * name,
711
+ v8::FunctionCallback callback) {
712
+ v8::Local<v8::Function> function =
713
+ NewFunctionTemplate (callback,
714
+ v8::Local<v8::Signature>(),
715
+ // TODO(TimothyGu): Investigate if SetMethod is ever
716
+ // used for constructors.
717
+ v8::ConstructorBehavior::kAllow ,
718
+ v8::SideEffectType::kHasNoSideEffect )->GetFunction ();
695
719
// kInternalized strings are created in the old space.
696
720
const v8::NewStringType type = v8::NewStringType::kInternalized ;
697
721
v8::Local<v8::String> name_string =
@@ -705,7 +729,24 @@ inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
705
729
v8::FunctionCallback callback) {
706
730
v8::Local<v8::Signature> signature = v8::Signature::New (isolate (), that);
707
731
v8::Local<v8::FunctionTemplate> t =
708
- NewFunctionTemplate (callback, signature, v8::ConstructorBehavior::kThrow );
732
+ NewFunctionTemplate (callback, signature, v8::ConstructorBehavior::kThrow ,
733
+ v8::SideEffectType::kHasSideEffect );
734
+ // kInternalized strings are created in the old space.
735
+ const v8::NewStringType type = v8::NewStringType::kInternalized ;
736
+ v8::Local<v8::String> name_string =
737
+ v8::String::NewFromUtf8 (isolate (), name, type).ToLocalChecked ();
738
+ that->PrototypeTemplate ()->Set (name_string, t);
739
+ t->SetClassName (name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility.
740
+ }
741
+
742
+ inline void Environment::SetProtoMethodNoSideEffect (
743
+ v8::Local<v8::FunctionTemplate> that,
744
+ const char * name,
745
+ v8::FunctionCallback callback) {
746
+ v8::Local<v8::Signature> signature = v8::Signature::New (isolate (), that);
747
+ v8::Local<v8::FunctionTemplate> t =
748
+ NewFunctionTemplate (callback, signature, v8::ConstructorBehavior::kThrow ,
749
+ v8::SideEffectType::kHasNoSideEffect );
709
750
// kInternalized strings are created in the old space.
710
751
const v8::NewStringType type = v8::NewStringType::kInternalized ;
711
752
v8::Local<v8::String> name_string =
@@ -717,7 +758,26 @@ inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
717
758
inline void Environment::SetTemplateMethod (v8::Local<v8::FunctionTemplate> that,
718
759
const char * name,
719
760
v8::FunctionCallback callback) {
720
- v8::Local<v8::FunctionTemplate> t = NewFunctionTemplate (callback);
761
+ v8::Local<v8::FunctionTemplate> t =
762
+ NewFunctionTemplate (callback, v8::Local<v8::Signature>(),
763
+ v8::ConstructorBehavior::kAllow ,
764
+ v8::SideEffectType::kHasSideEffect );
765
+ // kInternalized strings are created in the old space.
766
+ const v8::NewStringType type = v8::NewStringType::kInternalized ;
767
+ v8::Local<v8::String> name_string =
768
+ v8::String::NewFromUtf8 (isolate (), name, type).ToLocalChecked ();
769
+ that->Set (name_string, t);
770
+ t->SetClassName (name_string); // NODE_SET_METHOD() compatibility.
771
+ }
772
+
773
+ inline void Environment::SetTemplateMethodNoSideEffect (
774
+ v8::Local<v8::FunctionTemplate> that,
775
+ const char * name,
776
+ v8::FunctionCallback callback) {
777
+ v8::Local<v8::FunctionTemplate> t =
778
+ NewFunctionTemplate (callback, v8::Local<v8::Signature>(),
779
+ v8::ConstructorBehavior::kAllow ,
780
+ v8::SideEffectType::kHasNoSideEffect );
721
781
// kInternalized strings are created in the old space.
722
782
const v8::NewStringType type = v8::NewStringType::kInternalized ;
723
783
v8::Local<v8::String> name_string =
0 commit comments