Skip to content

Commit e19f71b

Browse files
bnoordhuistargos
authored andcommitted
v8: warn in Template::Set() on improper use
The next major release will make it a fatal error to use non-primitive values in function templates and object templates. Print a warning that includes the C and JS stack trace to tell people to upgrade their add-ons. The C stack trace is only printed on platforms that support it (the BSDs, OS X and Linux+glibc.) The warning can be disabled with the new `--nowarn_template_set` flag. Refs: nodejs#6216 PR-URL: nodejs#6277 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2d7abd9 commit e19f71b

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

deps/v8/src/api.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,16 @@ void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
10311031
i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true);
10321032
}
10331033
}
1034+
if (i::FLAG_warn_template_set &&
1035+
value_obj->IsJSReceiver() &&
1036+
!value_obj->IsTemplateInfo()) {
1037+
base::OS::PrintError(
1038+
"(node) v8::%sTemplate::Set() with non-primitive values is deprecated\n"
1039+
"(node) and will stop working in the next major release.\n",
1040+
templ->IsFunctionTemplateInfo() ? "Function" : "Object");
1041+
isolate->PrintStack(stderr, i::Isolate::kPrintStackConcise);
1042+
base::DumpBacktrace();
1043+
}
10341044
i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
10351045
value_obj,
10361046
static_cast<i::PropertyAttributes>(attribute));

deps/v8/src/flag-definitions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ struct MaybeBoolFlag {
172172
//
173173
#define FLAG FLAG_FULL
174174

175+
DEFINE_BOOL(warn_template_set, true,
176+
"warn on deprecated v8::Template::Set() use")
177+
175178
DEFINE_BOOL(experimental_extras, false,
176179
"enable code compiled in via v8_experimental_extra_library_files")
177180

0 commit comments

Comments
 (0)