Commit 4de391ef authored by jochen's avatar jochen Committed by Commit bot

Reland of [api] Restrict Template::Set to take templates or primitive values...

Reland of [api] Restrict Template::Set to take templates or primitive values (patchset #1 id:1 of https://codereview.chromium.org/1860003002/ )

Reason for revert:
node.js is updated now

Original issue's description:
> Revert of [api] Restrict Template::Set to take templates or primitive values (patchset #1 id:1 of https://codereview.chromium.org/1839983002/ )
>
> Reason for revert:
> Breaks node.js
>
> Original issue's description:
> > [api] Restrict Template::Set to take templates or primitive values
> >
> > Embedders that passed in non-primitive values should either use
> > getters/setters (templates) or install a native data property,
> > otherwise, the values would all result in cross-context leaks
> >
> > BUG=none
> > R=verwaest@chromium.org
> > LOG=y
> >
> > Committed: https://crrev.com/eebdee8eafa97849cc70c25f3fecf1b075bac248
> > Cr-Commit-Position: refs/heads/master@{#35244}
>
> TBR=verwaest@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=none
>
> Committed: https://crrev.com/e1674a24ca3cb92bb4e58d368b25767bd61a0dfa
> Cr-Commit-Position: refs/heads/master@{#35264}

TBR=verwaest@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=none

Review URL: https://codereview.chromium.org/1894993002

Cr-Commit-Position: refs/heads/master@{#35572}
parent 15defcc4
......@@ -4142,7 +4142,11 @@ enum Intrinsic {
*/
class V8_EXPORT Template : public Data {
public:
/** Adds a property to each instance created by this template.*/
/**
* Adds a property to each instance created by this template.
*
* The property must be defined either as a primitive value, or a template.
*/
void Set(Local<Name> name, Local<Data> value,
PropertyAttribute attributes = None);
V8_INLINE void Set(Isolate* isolate, const char* name, Local<Data> value);
......
......@@ -1029,13 +1029,13 @@ void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
ENTER_V8(isolate);
i::HandleScope scope(isolate);
auto value_obj = Utils::OpenHandle(*value);
CHECK(!value_obj->IsJSReceiver() || value_obj->IsTemplateInfo());
if (value_obj->IsObjectTemplateInfo()) {
templ->set_serial_number(i::Smi::FromInt(0));
if (templ->IsFunctionTemplateInfo()) {
i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true);
}
}
// TODO(dcarney): split api to allow values of v8::Value or v8::TemplateInfo.
i::ApiNatives::AddDataProperty(isolate, templ, Utils::OpenHandle(*name),
value_obj,
static_cast<i::PropertyAttributes>(attribute));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment