Exemple #1
0
 void ScriptSystem::AddToComponentMap(dtEntity::ComponentType ct, dtEntity::EntityId eid, v8::Handle<v8::Object> obj)
 {
    HandleScope scope;
    Persistent<Object> pobj = Persistent<Object>::New(obj);
    pobj.MakeWeak(this, &ComponentWrapperDestructor);
    V8::AdjustAmountOfExternalAllocatedMemory(sizeof(dtEntity::Component));
    mComponentMap[std::make_pair(ct, eid)] = pobj;
 }
Handle<Value> rr_v8_external_create(VALUE value) {
  rb_hash_aset(references, rb_obj_id(value), value);
  Local<Value> external(External::New((void *)value));
  Persistent<Value> record = Persistent<Value>::New(external);
  // V8::AdjustAmountOfExternalAllocatedMemory(100000000);
  record.MakeWeak(NULL, GCWeakReferenceCallback);
  return external;
}
Exemple #3
0
int Conv::BindToJavaObject(JNIEnv *jniEnv, jobject jLocal, Handle<Object> val, jobject *jGlobal) {
  int result = OK;
  Persistent<Object> pVal = Persistent<Object>::New(val);
  jobject ob = jniEnv->NewGlobalRef(jLocal);
  pVal.MakeWeak(ob, releaseJavaRef);
  val->SetPointerInInternalField(0, ob);
  jniEnv->SetLongField(jLocal, instHandle, asLong(pVal));
  *jGlobal = ob;
  return result;
}
Exemple #4
0
Handle<Value> JsEngine::AnyToV8(jsvalue v, int32_t contextId)
{
	if (v.type == JSVALUE_TYPE_EMPTY) {
		return Handle<Value>();
	}
	if (v.type == JSVALUE_TYPE_NULL) {
        return Null();
    }
    if (v.type == JSVALUE_TYPE_BOOLEAN) {
        return Boolean::New(v.value.i32);
    }
    if (v.type == JSVALUE_TYPE_INTEGER) {
        return Int32::New(v.value.i32);
    }
    if (v.type == JSVALUE_TYPE_NUMBER) {
        return Number::New(v.value.num);
    }
    if (v.type == JSVALUE_TYPE_STRING) {
        return String::New(v.value.str);
    }
    if (v.type == JSVALUE_TYPE_DATE) {
        return Date::New(v.value.num);
    }
	
    // Arrays are converted to JS native arrays.
    
    if (v.type == JSVALUE_TYPE_ARRAY) {
        Local<Array> a = Array::New(v.length);
        for(int i = 0; i < v.length; i++) {
            a->Set(i, AnyToV8(v.value.arr[i], contextId));
        }
        return a;        
    }
        
    // This is an ID to a managed object that lives inside the JsContext keep-alive
    // cache. We just wrap it and the pointer to the engine inside an External. A
    // managed error is still a CLR object so it is wrapped exactly as a normal
    // managed object.
    if (v.type == JSVALUE_TYPE_MANAGED || v.type == JSVALUE_TYPE_MANAGED_ERROR) {
		ManagedRef* ref = new ManagedRef(this, contextId, v.length);
		Local<Object> object = (*(managed_template_))->InstanceTemplate()->NewInstance();
		if (object.IsEmpty()) {
			return Null();
		}
		
		Persistent<Object> persistent = Persistent<Object>::New(object);
		persistent->SetInternalField(0, External::New(ref));
		persistent.MakeWeak(NULL, managed_destroy);
        return persistent;
    }

    return Null();
}
Exemple #5
0
void Shape::New(const v8::FunctionCallbackInfo<Value>& args)
{
  HandleScope scope;
  Handle<Object> self = args.Holder();
  Shape *shape;

  if (args[0]->IsExternal())
  {
    Local<External> ext = Local<External>::Cast(args[0]);
    void *ptr = ext->Value();
    shape = static_cast<Shape*>(ptr);
    shape->Wrap(args.Holder());
  }
  else
  {
    shapeObj *s = (shapeObj *)msSmallMalloc(sizeof(shapeObj));

    msInitShape(s);
    if(args.Length() >= 1) {
      s->type = args[0]->Int32Value();
    }
    else {
      s->type = MS_SHAPE_NULL;
    }

    shape = new Shape(s);
    shape->Wrap(self);
  }

  /* create the attribute template. should use ObjectWrap in future */
  Handle<ObjectTemplate> attributes_templ = ObjectTemplate::New();
  attributes_templ->SetInternalFieldCount(2);
  attributes_templ->SetNamedPropertyHandler(attributeGetValue,
                                            attributeSetValue);
  Handle<Object> attributes = attributes_templ->NewInstance();
  map<string, int> *attributes_map = new map<string, int>();
  attributes->SetInternalField(0, External::New(attributes_map));
  attributes->SetInternalField(1, External::New(shape->get()->values));  
  attributes->SetHiddenValue(String::New("__parent__"), self);

  if (shape->layer) {
    for (int i=0; i<shape->layer->numitems; ++i) {
      (*attributes_map)[string(shape->layer->items[i])] = i;
    }
  }

  Persistent<Object> pattributes;
  pattributes.Reset(Isolate::GetCurrent(), attributes);
  pattributes.MakeWeak(attributes_map, attributeWeakCallback);
  pattributes.MarkIndependent();

  self->Set(String::New("attributes"), attributes);
}
Handle<Value> def_timestep_image_map_constructor(const Arguments &args) {
	int arg_length = args.Length();
	Handle<Object> thiz = Handle<Object>::Cast(args.This());

	timestep_image_map *map = timestep_image_map_init();
	Local<External> m = External::New(map);
	thiz->SetInternalField(0, m);
	
	map->x = args[1]->NumberValue();
	map->y = args[2]->NumberValue();
	map->width = args[3]->NumberValue();
	map->height = args[4]->NumberValue();

	// to support both marcus-spritemaps (TM) as well as 
	// normal old style image maps (those that don't have explicit margins),
	// check the argument length.  If there are only 6 arguments, there are not
	// specified margins.  Set them to 0.
	Handle<Value> url_val;
	if (arg_length == 6) {
		url_val = args[5];
		map->margin_top = 0;
		map->margin_right = 0;
		map->margin_bottom = 0;
		map->margin_left = 0;
	} else {
		url_val = args[9];
		map->margin_top = args[5]->NumberValue();
		map->margin_right = args[6]->NumberValue();
		map->margin_bottom = args[7]->NumberValue();
		map->margin_left = args[8]->NumberValue();
	}
	
	// WARNING: must not forget to free this at some point
	String::Utf8Value str(url_val);
	map->url = strdup(ToCString(str));

	Persistent<Object> ref = Persistent<Object>::New(thiz);
	ref.MakeWeak(map, image_map_finalize);
	
	return thiz;
}
Exemple #7
0
// コンストラクタ
TJSObject::TJSObject(Handle<Object> obj, const tTJSVariant &variant) : TJSBase(variant)
{
	wrap(obj);
	Persistent<Object> ref = Persistent<Object>::New(obj);
	ref.MakeWeak(this, release);
}
Exemple #8
0
extern "C" void test(WeakReferenceCallback* cleanup) {
    Persistent<Context> c = createContext();
    HandleScope handle_scope;
    Persistent<Object> o = Persistent<Object>::New(Object::New());
    o.MakeWeak(cleanup, disposeHandle);
}
Exemple #9
0
extern "C" void makeWeak(Persistent<Value> prst, CALLBACK* cleanup) {
    prst.MakeWeak(cleanup, disposeHandle);
//    cout << "Hello from makeWeak c++" << endl;
}