Browse Source

node: don't malloc in FromConstructorTemplate

* allocate space for argv on the stack
* move the declaration to node_internals.h
v0.9.10-release
Ben Noordhuis 12 years ago
parent
commit
aff8d9e716
  1. 20
      src/node.cc
  2. 12
      src/node.h
  3. 4
      src/node_internals.h

20
src/node.cc

@ -863,22 +863,14 @@ Local<Value> WinapiErrnoException(int errorno,
#endif
Handle<Value> FromConstructorTemplate(Persistent<FunctionTemplate>& t,
Handle<Value> FromConstructorTemplate(Persistent<FunctionTemplate> t,
const Arguments& args) {
HandleScope scope;
const int argc = args.Length();
Local<Value>* argv = new Local<Value>[argc];
for (int i = 0; i < argc; ++i) {
argv[i] = args[i];
}
Local<Object> instance = t->GetFunction()->NewInstance(argc, argv);
delete[] argv;
return scope.Close(instance);
Local<Value> argv[32];
unsigned argc = args.Length();
if (argc > ARRAY_SIZE(argv)) argc = ARRAY_SIZE(argv);
for (unsigned i = 0; i < argc; ++i) argv[i] = args[i];
return scope.Close(t->GetFunction()->NewInstance(argc, argv));
}

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);
/**
* 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(
const v8::Local<v8::Value> &v) {
v8::Persistent<v8::Function> *fn = new v8::Persistent<v8::Function>();

4
src/node_internals.h

@ -97,6 +97,10 @@ inline static v8::Handle<v8::Value> ThrowRangeError(const char* errmsg) {
abort(); \
}
v8::Handle<v8::Value> FromConstructorTemplate(
v8::Persistent<v8::FunctionTemplate> t,
const v8::Arguments& args);
} // namespace node
#endif // SRC_NODE_INTERNALS_H_

Loading…
Cancel
Save