Skip to content

Commit 44f781d

Browse files
bnoordhuisofrobots
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: #6216 PR-URL: #6277 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b2f7c32 commit 44f781d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

deps/v8/src/api.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,16 @@ void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
10361036
i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true);
10371037
}
10381038
}
1039+
if (i::FLAG_warn_template_set &&
1040+
value_obj->IsJSReceiver() &&
1041+
!value_obj->IsTemplateInfo()) {
1042+
base::OS::PrintError(
1043+
"(node) v8::%sTemplate::Set() with non-primitive values is deprecated\n"
1044+
"(node) and will stop working in the next major release.\n",
1045+
templ->IsFunctionTemplateInfo() ? "Function" : "Object");
1046+
isolate->PrintStack(stderr, i::Isolate::kPrintStackConcise);
1047+
base::DumpBacktrace();
1048+
}
10391049
// TODO(dcarney): split api to allow values of v8::Value or v8::TemplateInfo.
10401050
i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
10411051
value_obj,

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)