Hi,
suppose I have wrapped a vector TJsVec and there's a function static void
multiply(const v8::FunctionCallbackInfo<v8::Value>& Args); that returns a
new TJsVec, scaled by a scalar:
void TJsVec::multiply(const FunctionCallbackInfo<Value>& Args) {
Isolate* Isolate = Isolate::GetCurrent();
HandleScope Scope(Isolate);
/* error checking -- make sure Args.Length() >= 1 and Args[0] is a number
*/
TJsVec* JsVec = ... /* unwraps the object */
const double Scalar = Args[0]->NumberValue();
TFloatVector ResV; // ResV = JsVec->Vec * Scalar
... /* scales JsVec->Vec by scalar using internal linear algebra library
*/
TJsVec* JsResV = new TJsVec(ResV);
JsResV->Wrap(Args.Holder()); // (1)
// (2)
Args.GetReturnValue().Set(JsResV); // (3)
}
Note that TJsVec is derived from node::ObjectWrap, i.e. we have class
TJsVec : public node::ObjectWrap { ... };.
I have several questions regarding this code:
(*) What exactly does the line JsResV->Wrap(Args.Holder()) do? Why do we
pass it Args.Holder()?
(*) What does Args.GetReturnValue().Set(JsResV); do?
(*) And, most important, suppose I executed Javascript function in the
place (2). *Could V8 garbage-collected JsResV?* I.e. is object elligible
for delition at (2) -- immediately after creation and before the function
"returns" it in (3)?
Furher, should I move the line (3) immediately after creating the object?
Blaz.
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/f4da084b-1579-4875-997c-87e9ec29de7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.