Commit 0aef24e2 authored by dcarney's avatar dcarney Committed by Commit bot

CHECK that FunctionTemplates are not modified after first instantiation

BUG=

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

Cr-Commit-Position: refs/heads/master@{#26237}
parent 5d14e4bc
...@@ -3703,6 +3703,9 @@ typedef bool (*IndexedSecurityCallback)(Local<Object> host, ...@@ -3703,6 +3703,9 @@ typedef bool (*IndexedSecurityCallback)(Local<Object> host,
* temporary functions that can be collected using Scripts is * temporary functions that can be collected using Scripts is
* preferred. * preferred.
* *
* Any modification of a FunctionTemplate after first instantiation will trigger
*a crash.
*
* A FunctionTemplate can have properties, these properties are added to the * A FunctionTemplate can have properties, these properties are added to the
* function object when it is created. * function object when it is created.
* *
......
...@@ -797,10 +797,19 @@ Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() { ...@@ -797,10 +797,19 @@ Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
} }
static void EnsureNotInstantiated(i::Handle<i::FunctionTemplateInfo> info,
const char* func) {
Utils::ApiCheck(!info->instantiated(), func,
"FunctionTemplate already instantiated");
}
void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit");
i::Isolate* isolate = info->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); info->set_parent_template(*Utils::OpenHandle(*value));
} }
...@@ -910,7 +919,9 @@ int TypeSwitch::match(v8::Handle<Value> value) { ...@@ -910,7 +919,9 @@ int TypeSwitch::match(v8::Handle<Value> value) {
void FunctionTemplate::SetCallHandler(FunctionCallback callback, void FunctionTemplate::SetCallHandler(FunctionCallback callback,
v8::Handle<Value> data) { v8::Handle<Value> data) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler");
i::Isolate* isolate = info->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
i::Handle<i::Struct> struct_obj = i::Handle<i::Struct> struct_obj =
...@@ -922,7 +933,7 @@ void FunctionTemplate::SetCallHandler(FunctionCallback callback, ...@@ -922,7 +933,7 @@ void FunctionTemplate::SetCallHandler(FunctionCallback callback,
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
} }
obj->set_data(*Utils::OpenHandle(*data)); obj->set_data(*Utils::OpenHandle(*data));
Utils::OpenHandle(this)->set_call_code(*obj); info->set_call_code(*obj);
} }
...@@ -986,37 +997,47 @@ Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() { ...@@ -986,37 +997,47 @@ Local<ObjectTemplate> FunctionTemplate::InstanceTemplate() {
void FunctionTemplate::SetLength(int length) { void FunctionTemplate::SetLength(int length) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::SetLength");
auto isolate = info->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
Utils::OpenHandle(this)->set_length(length); info->set_length(length);
} }
void FunctionTemplate::SetClassName(Handle<String> name) { void FunctionTemplate::SetClassName(Handle<String> name) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::SetClassName");
auto isolate = info->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
Utils::OpenHandle(this)->set_class_name(*Utils::OpenHandle(*name)); info->set_class_name(*Utils::OpenHandle(*name));
} }
void FunctionTemplate::SetHiddenPrototype(bool value) { void FunctionTemplate::SetHiddenPrototype(bool value) {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::SetHiddenPrototype");
auto isolate = info->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
Utils::OpenHandle(this)->set_hidden_prototype(value); info->set_hidden_prototype(value);
} }
void FunctionTemplate::ReadOnlyPrototype() { void FunctionTemplate::ReadOnlyPrototype() {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::ReadOnlyPrototype");
auto isolate = info->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
Utils::OpenHandle(this)->set_read_only_prototype(true); info->set_read_only_prototype(true);
} }
void FunctionTemplate::RemovePrototype() { void FunctionTemplate::RemovePrototype() {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::RemovePrototype");
auto isolate = info->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
Utils::OpenHandle(this)->set_remove_prototype(true); info->set_remove_prototype(true);
} }
...@@ -1183,10 +1204,8 @@ static void ObjectTemplateSetNamedPropertyHandler(ObjectTemplate* templ, ...@@ -1183,10 +1204,8 @@ static void ObjectTemplateSetNamedPropertyHandler(ObjectTemplate* templ,
i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
EnsureConstructor(isolate, templ); auto cons = EnsureConstructor(isolate, templ);
i::FunctionTemplateInfo* constructor = EnsureNotInstantiated(cons, "ObjectTemplateSetNamedPropertyHandler");
i::FunctionTemplateInfo::cast(Utils::OpenHandle(templ)->constructor());
i::Handle<i::FunctionTemplateInfo> cons(constructor);
i::Handle<i::Struct> struct_obj = i::Handle<i::Struct> struct_obj =
isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE);
i::Handle<i::InterceptorInfo> obj = i::Handle<i::InterceptorInfo> obj =
...@@ -1229,10 +1248,8 @@ void ObjectTemplate::MarkAsUndetectable() { ...@@ -1229,10 +1248,8 @@ void ObjectTemplate::MarkAsUndetectable() {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
EnsureConstructor(isolate, this); auto cons = EnsureConstructor(isolate, this);
i::FunctionTemplateInfo* constructor = EnsureNotInstantiated(cons, "v8::ObjectTemplate::MarkAsUndetectable");
i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
i::Handle<i::FunctionTemplateInfo> cons(constructor);
cons->set_undetectable(true); cons->set_undetectable(true);
} }
...@@ -1245,7 +1262,8 @@ void ObjectTemplate::SetAccessCheckCallbacks( ...@@ -1245,7 +1262,8 @@ void ObjectTemplate::SetAccessCheckCallbacks(
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
EnsureConstructor(isolate, this); auto cons = EnsureConstructor(isolate, this);
EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetAccessCheckCallbacks");
i::Handle<i::Struct> struct_info = i::Handle<i::Struct> struct_info =
isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE);
...@@ -1260,9 +1278,6 @@ void ObjectTemplate::SetAccessCheckCallbacks( ...@@ -1260,9 +1278,6 @@ void ObjectTemplate::SetAccessCheckCallbacks(
} }
info->set_data(*Utils::OpenHandle(*data)); info->set_data(*Utils::OpenHandle(*data));
i::FunctionTemplateInfo* constructor =
i::FunctionTemplateInfo::cast(Utils::OpenHandle(this)->constructor());
i::Handle<i::FunctionTemplateInfo> cons(constructor);
cons->set_access_check_info(*info); cons->set_access_check_info(*info);
cons->set_needs_access_check(turned_on_by_default); cons->set_needs_access_check(turned_on_by_default);
} }
...@@ -1273,10 +1288,8 @@ void ObjectTemplate::SetHandler( ...@@ -1273,10 +1288,8 @@ void ObjectTemplate::SetHandler(
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
EnsureConstructor(isolate, this); auto cons = EnsureConstructor(isolate, this);
i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetHandler");
Utils::OpenHandle(this)->constructor());
i::Handle<i::FunctionTemplateInfo> cons(constructor);
i::Handle<i::Struct> struct_obj = i::Handle<i::Struct> struct_obj =
isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE); isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE);
i::Handle<i::InterceptorInfo> obj = i::Handle<i::InterceptorInfo> obj =
...@@ -1305,10 +1318,8 @@ void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback, ...@@ -1305,10 +1318,8 @@ void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback,
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
EnsureConstructor(isolate, this); auto cons = EnsureConstructor(isolate, this);
i::FunctionTemplateInfo* constructor = i::FunctionTemplateInfo::cast( EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetCallAsFunctionHandler");
Utils::OpenHandle(this)->constructor());
i::Handle<i::FunctionTemplateInfo> cons(constructor);
i::Handle<i::Struct> struct_obj = i::Handle<i::Struct> struct_obj =
isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
i::Handle<i::CallHandlerInfo> obj = i::Handle<i::CallHandlerInfo> obj =
......
...@@ -2243,6 +2243,7 @@ Handle<JSFunction> Factory::CreateApiFunction( ...@@ -2243,6 +2243,7 @@ Handle<JSFunction> Factory::CreateApiFunction(
Handle<Code> code = isolate()->builtins()->HandleApiCall(); Handle<Code> code = isolate()->builtins()->HandleApiCall();
Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi(); Handle<Code> construct_stub = isolate()->builtins()->JSConstructStubApi();
obj->set_instantiated(true);
Handle<JSFunction> result; Handle<JSFunction> result;
if (obj->remove_prototype()) { if (obj->remove_prototype()) {
result = NewFunctionWithoutPrototype(empty_string(), code); result = NewFunctionWithoutPrototype(empty_string(), code);
......
...@@ -5636,6 +5636,7 @@ BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype, ...@@ -5636,6 +5636,7 @@ BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
kRemovePrototypeBit) kRemovePrototypeBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache, BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache,
kDoNotCacheBit) kDoNotCacheBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, instantiated, kInstantiatedBit)
BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_expression, BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_expression,
kIsExpressionBit) kIsExpressionBit)
BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel, BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel,
......
...@@ -927,6 +927,7 @@ void FunctionTemplateInfo::FunctionTemplateInfoPrint( ...@@ -927,6 +927,7 @@ void FunctionTemplateInfo::FunctionTemplateInfoPrint(
os << "\n - hidden_prototype: " << (hidden_prototype() ? "true" : "false"); os << "\n - hidden_prototype: " << (hidden_prototype() ? "true" : "false");
os << "\n - undetectable: " << (undetectable() ? "true" : "false"); os << "\n - undetectable: " << (undetectable() ? "true" : "false");
os << "\n - need_access_check: " << (needs_access_check() ? "true" : "false"); os << "\n - need_access_check: " << (needs_access_check() ? "true" : "false");
os << "\n - instantiated: " << (instantiated() ? "true" : "false");
os << "\n"; os << "\n";
} }
......
...@@ -10607,6 +10607,7 @@ class FunctionTemplateInfo: public TemplateInfo { ...@@ -10607,6 +10607,7 @@ class FunctionTemplateInfo: public TemplateInfo {
DECL_BOOLEAN_ACCESSORS(read_only_prototype) DECL_BOOLEAN_ACCESSORS(read_only_prototype)
DECL_BOOLEAN_ACCESSORS(remove_prototype) DECL_BOOLEAN_ACCESSORS(remove_prototype)
DECL_BOOLEAN_ACCESSORS(do_not_cache) DECL_BOOLEAN_ACCESSORS(do_not_cache)
DECL_BOOLEAN_ACCESSORS(instantiated)
DECLARE_CAST(FunctionTemplateInfo) DECLARE_CAST(FunctionTemplateInfo)
...@@ -10647,6 +10648,7 @@ class FunctionTemplateInfo: public TemplateInfo { ...@@ -10647,6 +10648,7 @@ class FunctionTemplateInfo: public TemplateInfo {
static const int kReadOnlyPrototypeBit = 3; static const int kReadOnlyPrototypeBit = 3;
static const int kRemovePrototypeBit = 4; static const int kRemovePrototypeBit = 4;
static const int kDoNotCacheBit = 5; static const int kDoNotCacheBit = 5;
static const int kInstantiatedBit = 6;
DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
}; };
......
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