Skip to content

Commit 967a155

Browse files
bnoordhuisjasnell
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 9697876 commit 967a155

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

deps/v8/src/api.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,17 @@ void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
939939
i::Isolate* isolate = templ->GetIsolate();
940940
ENTER_V8(isolate);
941941
i::HandleScope scope(isolate);
942+
auto value_obj = Utils::OpenHandle(*value);
943+
if (i::FLAG_warn_template_set &&
944+
value_obj->IsJSReceiver() &&
945+
!value_obj->IsTemplateInfo()) {
946+
base::OS::PrintError(
947+
"(node) v8::%sTemplate::Set() with non-primitive values is deprecated\n"
948+
"(node) and will stop working in the next major release.\n",
949+
templ->IsFunctionTemplateInfo() ? "Function" : "Object");
950+
isolate->PrintStack(stderr, i::Isolate::kPrintStackConcise);
951+
base::DumpBacktrace();
952+
}
942953
// TODO(dcarney): split api to allow values of v8::Value or v8::TemplateInfo.
943954
i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
944955
Utils::OpenHandle(*value),

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)