Skip to content

Commit

Permalink
v8: warn in Template::Set() on improper use
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bnoordhuis authored and targos committed Jun 3, 2016
1 parent 6e64729 commit 7cb0611
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions deps/v8/src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,16 @@ void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true);
}
}
if (i::FLAG_warn_template_set &&
value_obj->IsJSReceiver() &&
!value_obj->IsTemplateInfo()) {
base::OS::PrintError(
"(node) v8::%sTemplate::Set() with non-primitive values is deprecated\n"
"(node) and will stop working in the next major release.\n",
templ->IsFunctionTemplateInfo() ? "Function" : "Object");
isolate->PrintStack(stderr, i::Isolate::kPrintStackConcise);
base::DumpBacktrace();
}
// TODO(dcarney): split api to allow values of v8::Value or v8::TemplateInfo.
i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
value_obj,
Expand Down
3 changes: 3 additions & 0 deletions deps/v8/src/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ struct MaybeBoolFlag {
//
#define FLAG FLAG_FULL

DEFINE_BOOL(warn_template_set, true,
"warn on deprecated v8::Template::Set() use")

DEFINE_BOOL(experimental_extras, false,
"enable code compiled in via v8_experimental_extra_library_files")

Expand Down

0 comments on commit 7cb0611

Please sign in to comment.