summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2016-04-15 19:40:01 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2016-04-18 11:39:52 +0200
commit642076f2aff3cddf93dd7cb6b1a332f8064ab39f (patch)
tree4f47a6234a1eab74cd881b6ccbb48de38d614fd6 /src
parent15f13cd74a8bb9e62b871076328447b4ead7e8b6 (diff)
downloadandroid-node-v8-642076f2aff3cddf93dd7cb6b1a332f8064ab39f.tar.gz
android-node-v8-642076f2aff3cddf93dd7cb6b1a332f8064ab39f.tar.bz2
android-node-v8-642076f2aff3cddf93dd7cb6b1a332f8064ab39f.zip
src: don't set non-primitive values on templates
V8 is going to disallow non-primitive values on v8::FunctionTemplate and v8::ObjectTemplate because those can't be shared across contexts. Fixes: https://github.com/nodejs/node/issues/6216 PR-URL: https://github.com/nodejs/node/pull/6228 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/env-inl.h14
-rw-r--r--src/node.h21
-rw-r--r--src/node_http_parser.cc2
3 files changed, 23 insertions, 14 deletions
diff --git a/src/env-inl.h b/src/env-inl.h
index 475e8e83f5..2c6248ae60 100644
--- a/src/env-inl.h
+++ b/src/env-inl.h
@@ -507,27 +507,25 @@ inline void Environment::SetProtoMethod(v8::Local<v8::FunctionTemplate> that,
const char* name,
v8::FunctionCallback callback) {
v8::Local<v8::Signature> signature = v8::Signature::New(isolate(), that);
- v8::Local<v8::Function> function =
- NewFunctionTemplate(callback, signature)->GetFunction();
+ v8::Local<v8::FunctionTemplate> t = NewFunctionTemplate(callback, signature);
// kInternalized strings are created in the old space.
const v8::NewStringType type = v8::NewStringType::kInternalized;
v8::Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
- that->PrototypeTemplate()->Set(name_string, function);
- function->SetName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility.
+ that->PrototypeTemplate()->Set(name_string, t);
+ t->SetClassName(name_string); // NODE_SET_PROTOTYPE_METHOD() compatibility.
}
inline void Environment::SetTemplateMethod(v8::Local<v8::FunctionTemplate> that,
const char* name,
v8::FunctionCallback callback) {
- v8::Local<v8::Function> function =
- NewFunctionTemplate(callback)->GetFunction();
+ v8::Local<v8::FunctionTemplate> t = NewFunctionTemplate(callback);
// kInternalized strings are created in the old space.
const v8::NewStringType type = v8::NewStringType::kInternalized;
v8::Local<v8::String> name_string =
v8::String::NewFromUtf8(isolate(), name, type).ToLocalChecked();
- that->Set(name_string, function);
- function->SetName(name_string); // NODE_SET_METHOD() compatibility.
+ that->Set(name_string, t);
+ t->SetClassName(name_string); // NODE_SET_METHOD() compatibility.
}
inline v8::Local<v8::Object> Environment::NewInternalFieldObject() {
diff --git a/src/node.h b/src/node.h
index 59df8e18b4..529ee75f27 100644
--- a/src/node.h
+++ b/src/node.h
@@ -240,8 +240,20 @@ NODE_EXTERN void RunAtExit(Environment* env);
while (0)
// Used to be a macro, hence the uppercase name.
-template <typename TypeName>
-inline void NODE_SET_METHOD(const TypeName& recv,
+inline void NODE_SET_METHOD(v8::Local<v8::Template> recv,
+ const char* name,
+ v8::FunctionCallback callback) {
+ v8::Isolate* isolate = v8::Isolate::GetCurrent();
+ v8::HandleScope handle_scope(isolate);
+ v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate,
+ callback);
+ v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
+ t->SetClassName(fn_name);
+ recv->Set(fn_name, t);
+}
+
+// Used to be a macro, hence the uppercase name.
+inline void NODE_SET_METHOD(v8::Local<v8::Object> recv,
const char* name,
v8::FunctionCallback callback) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
@@ -265,10 +277,9 @@ inline void NODE_SET_PROTOTYPE_METHOD(v8::Local<v8::FunctionTemplate> recv,
v8::Local<v8::Signature> s = v8::Signature::New(isolate, recv);
v8::Local<v8::FunctionTemplate> t =
v8::FunctionTemplate::New(isolate, callback, v8::Local<v8::Value>(), s);
- v8::Local<v8::Function> fn = t->GetFunction();
- recv->PrototypeTemplate()->Set(v8::String::NewFromUtf8(isolate, name), fn);
v8::Local<v8::String> fn_name = v8::String::NewFromUtf8(isolate, name);
- fn->SetName(fn_name);
+ t->SetClassName(fn_name);
+ recv->PrototypeTemplate()->Set(v8::String::NewFromUtf8(isolate, name), t);
}
#define NODE_SET_PROTOTYPE_METHOD node::NODE_SET_PROTOTYPE_METHOD
diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc
index 4087ed263f..7d30cfd99e 100644
--- a/src/node_http_parser.cc
+++ b/src/node_http_parser.cc
@@ -759,7 +759,7 @@ void InitHttpParser(Local<Object> target,
methods->Set(num, FIXED_ONE_BYTE_STRING(env->isolate(), #string));
HTTP_METHOD_MAP(V)
#undef V
- t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "methods"), methods);
+ target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "methods"), methods);
env->SetProtoMethod(t, "close", Parser::Close);
env->SetProtoMethod(t, "execute", Parser::Execute);