node: don't malloc in FromConstructorTemplate
* allocate space for argv on the stack * move the declaration to node_internals.h
This commit is contained in:
parent
d5a5ae3c11
commit
aff8d9e716
20
src/node.cc
20
src/node.cc
@ -863,22 +863,14 @@ Local<Value> WinapiErrnoException(int errorno,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
Handle<Value> FromConstructorTemplate(Persistent<FunctionTemplate>& t,
|
Handle<Value> FromConstructorTemplate(Persistent<FunctionTemplate> t,
|
||||||
const Arguments& args) {
|
const Arguments& args) {
|
||||||
HandleScope scope;
|
HandleScope scope;
|
||||||
|
Local<Value> argv[32];
|
||||||
const int argc = args.Length();
|
unsigned argc = args.Length();
|
||||||
Local<Value>* argv = new Local<Value>[argc];
|
if (argc > ARRAY_SIZE(argv)) argc = ARRAY_SIZE(argv);
|
||||||
|
for (unsigned i = 0; i < argc; ++i) argv[i] = args[i];
|
||||||
for (int i = 0; i < argc; ++i) {
|
return scope.Close(t->GetFunction()->NewInstance(argc, argv));
|
||||||
argv[i] = args[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
Local<Object> instance = t->GetFunction()->NewInstance(argc, argv);
|
|
||||||
|
|
||||||
delete[] argv;
|
|
||||||
|
|
||||||
return scope.Close(instance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
12
src/node.h
12
src/node.h
@ -150,18 +150,6 @@ NODE_EXTERN ssize_t DecodeWrite(char *buf,
|
|||||||
v8::Local<v8::Object> BuildStatsObject(const uv_statbuf_t* s);
|
v8::Local<v8::Object> BuildStatsObject(const uv_statbuf_t* s);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call this when your constructor is invoked as a regular function, e.g.
|
|
||||||
* Buffer(10) instead of new Buffer(10).
|
|
||||||
* @param constructorTemplate Constructor template to instantiate from.
|
|
||||||
* @param args The arguments object passed to your constructor.
|
|
||||||
* @see v8::Arguments::IsConstructCall
|
|
||||||
*/
|
|
||||||
v8::Handle<v8::Value> FromConstructorTemplate(
|
|
||||||
v8::Persistent<v8::FunctionTemplate>& constructorTemplate,
|
|
||||||
const v8::Arguments& args);
|
|
||||||
|
|
||||||
|
|
||||||
static inline v8::Persistent<v8::Function>* cb_persist(
|
static inline v8::Persistent<v8::Function>* cb_persist(
|
||||||
const v8::Local<v8::Value> &v) {
|
const v8::Local<v8::Value> &v) {
|
||||||
v8::Persistent<v8::Function> *fn = new v8::Persistent<v8::Function>();
|
v8::Persistent<v8::Function> *fn = new v8::Persistent<v8::Function>();
|
||||||
|
@ -97,6 +97,10 @@ inline static v8::Handle<v8::Value> ThrowRangeError(const char* errmsg) {
|
|||||||
abort(); \
|
abort(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Handle<v8::Value> FromConstructorTemplate(
|
||||||
|
v8::Persistent<v8::FunctionTemplate> t,
|
||||||
|
const v8::Arguments& args);
|
||||||
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
||||||
#endif // SRC_NODE_INTERNALS_H_
|
#endif // SRC_NODE_INTERNALS_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user