Ok, so I have the following code. The function "Delete" is a function property of the Point object, to ensure proper destruction of the c++ object.
At point (2) i am checking whether the js variable is a global variable and set the value to Null(). Is there a way to set a local function scope js variable declared with "var" keyword to null through the c++ code ? //--------------------------------------------------------------- #define UNWRAP_INTERNAL_FIELD(holder, retval, pointer) \ HandleScope handle_scope; \ Local<Object> self = holder; \ if (self->InternalFieldCount() != 1 || self->GetInternalField(0)->IsNull() == true || self->GetInternalField(0)->IsUndefined() == true) \ return retval; \ Local<External> wrap = Local<External>::Cast(self->GetInternalField(0)); \ Point* pointer = static_cast<Point*>(wrap->Value()); //--------------------------------------------------------------- static Handle<Value> Delete(const Arguments &args) { UNWRAP_INTERNAL_FIELD(args.Holder(), Null(), p); // (1) Clear args[0] object properties and functions Local<Array> array = self->GetPropertyNames(); for (int i = 0; (uint32_t)i < array->Length(); i++) self->ForceDelete(array->Get(i)); // (2) If args[0] is a global object then remove the object form global scope Local<Object> global = self->CreationContext()->Global(); array = global->GetPropertyNames(); for (int i = array->Length()-1; i >= 0; i--) { HandleScope handle_scope; Local<Value> name = array->Get(i); Local<Object> obj = global->Get(name)->ToObject(); if (obj->InternalFieldCount() == 1 && obj->GetInternalField(0)->IsNull() == false) { Local<External> _wrap = Local<External>::Cast(obj->GetInternalField(0)); if (wrap->Value() == _wrap->Value()) { global->Set(name, Null()); } } } // (3) Delete the c++ object and call its destructors delete p; // (4) SetInternalField to null self->SetInternalField(0, Null()); return Boolean::New(true); } -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users