本文整理汇总了C++中Local::SetInternalField方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::SetInternalField方法的具体用法?C++ Local::SetInternalField怎么用?C++ Local::SetInternalField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::SetInternalField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ObjectWrap
JsSprite::JsSprite(Isolate * isolate, Local<Object> handle)
: ObjectWrap(handle), _texture(nullptr), _sprite()
{
assert(handle->InternalFieldCount() > 1);
handle->SetInternalField(0, External::New(isolate, &_sprite));
handle->SetInternalField(1, External::New(isolate, this));
}
示例2: JSExceptionInvalidAttributeType
v8::Local<v8::Object>
JSZAttribute::createInstance(v8::Isolate *isolate, std::shared_ptr<ZCLAttribute> &zclAttribute) {
if (zclAttribute->getZCLType() != getZCLType()) {
throw JSExceptionInvalidAttributeType(getName(), zclAttribute->getZCLType(), getZCLType());
}
Local<ObjectTemplate> zAttributeT = Local<FunctionTemplate>::New(isolate, functionTemplate)->InstanceTemplate();
Local<Object> zAttributeInstance = zAttributeT->NewInstance();
zAttributeInstance->SetInternalField(0, External::New(isolate, zclAttribute.get()));
zAttributeInstance->SetInternalField(1, External::New(isolate, this));
return zAttributeInstance;
}
示例3:
Local<Object> ItemObject::createInstance()
{
HandleScope handleScope;
// Create the function template
Local<FunctionTemplate> functionTemplate = FunctionTemplate::New();
functionTemplate->SetClassName(String::New("Item"));
// Create the object template
Local<ObjectTemplate> objectTemplate = functionTemplate->InstanceTemplate();
objectTemplate->SetInternalFieldCount(1);
// Create an object instance
Local<Object> objectInstance = objectTemplate->NewInstance();
objectInstance->SetInternalField(0, External::New(this));
// Add functions to object instance
/*
Local<FunctionTemplate> printTemplate = FunctionTemplate::New(print);
Local<Function> printFunction = printTemplate->GetFunction();
objectInstance->Set(String::New("print"), printFunction);
Local<FunctionTemplate> inputTemplate = FunctionTemplate::New(input);
Local<Function> inputFunction = inputTemplate->GetFunction();
objectInstance->Set(String::New("input"), inputFunction);
*/
return handleScope.Close(objectInstance);
}
示例4: Link
void ObjectManager::Link(const Local<Object>& object, uint32_t javaObjectID, jclass clazz)
{
auto isolate = Isolate::GetCurrent();
DEBUG_WRITE("Linking js object: %d and java instance id: %d", object->GetIdentityHash(), javaObjectID);
JEnv env;
auto jsInstanceInfo = new JSInstanceInfo();
jsInstanceInfo->JavaObjectID = javaObjectID;
jsInstanceInfo->clazz = clazz;
auto objectHandle = new Persistent<Object>(isolate, object);
auto state = new ObjectWeakCallbackState(this, jsInstanceInfo, objectHandle);
objectHandle->SetWeak(state, JSObjectWeakCallbackStatic);
auto jsInfoIdx = static_cast<int>(MetadataNodeKeys::JsInfo);
bool alreadyLinked = !object->GetInternalField(jsInfoIdx)->IsUndefined();
//ASSERT_MESSAGE(alreadyLinked, "object should not have been linked before");
auto jsInfo = External::New(isolate, jsInstanceInfo);
object->SetInternalField(jsInfoIdx, jsInfo);
idToObject.insert(make_pair(javaObjectID, objectHandle));
}
示例5:
Image *Image::New(FIBITMAP* dib) {
HandleScope scope;
Local<Value> arg = Integer::NewFromUnsigned(0);
Local<Object> obj = constructor_template->GetFunction()->NewInstance(1, &arg);
Image *image = ObjectWrap::Unwrap<Image>(obj);
image->dib = dib;
int w,h,pitch;
FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib);
obj->SetInternalField(0, External::New(dib));
obj->Set(JS_STR("width"), JS_INT(w=FreeImage_GetWidth(dib)));
obj->Set(JS_STR("height"), JS_INT(h=FreeImage_GetHeight(dib)));
obj->Set(JS_STR("bpp"), JS_INT((int)FreeImage_GetBPP(dib)));
obj->Set(JS_STR("pitch"), JS_INT(pitch=FreeImage_GetPitch(dib)));
obj->Set(JS_STR("type"), JS_INT(type));
obj->Set(JS_STR("redMask"), JS_INT((int)FreeImage_GetRedMask(dib)));
obj->Set(JS_STR("greenMask"), JS_INT((int)FreeImage_GetGreenMask(dib)));
obj->Set(JS_STR("blueMask"), JS_INT((int)FreeImage_GetBlueMask(dib)));
BYTE *bits=FreeImage_GetBits(dib);
node::Buffer *buf = node::Buffer::New((char*)bits,h*pitch);
obj->Set(JS_STR("buffer"), buf->handle_);
return image;
}
示例6: handle_scope
/**
* Utility function that wraps a C++ http request object in a
* JavaScript object.
*/
Local<Object> JsHttpRequestProcessor::WrapRequest(HttpRequest* request) {
// Local scope for temporary handles.
EscapableHandleScope handle_scope(GetIsolate());
// Fetch the template for creating JavaScript http request wrappers.
// It only has to be created once, which we do on demand.
if (request_template_.IsEmpty()) {
Local<ObjectTemplate> raw_template = MakeRequestTemplate(GetIsolate());
request_template_.Reset(GetIsolate(), raw_template);
}
Local<ObjectTemplate> templ =
Local<ObjectTemplate>::New(GetIsolate(), request_template_);
// Create an empty http request wrapper.
Local<Object> result =
templ->NewInstance(GetIsolate()->GetCurrentContext()).ToLocalChecked();
// Wrap the raw C++ pointer in an External so it can be referenced
// from within JavaScript.
Local<External> request_ptr = External::New(GetIsolate(), request);
// Store the request pointer in the JavaScript wrapper.
result->SetInternalField(0, request_ptr);
// Return the result through the current handle scope. Since each
// of these handles will go away when the handle scope is deleted
// we need to call Close to let one, the result, escape into the
// outer handle scope.
return handle_scope.Escape(result);
}
示例7: Link
void ObjectManager::Link(const Local<Object>& object, uint32_t javaObjectID, jclass clazz)
{
int internalFieldCound = NativeScriptExtension::GetInternalFieldCount(object);
const int count = static_cast<int>(MetadataNodeKeys::END);
if (internalFieldCound != count)
{
string errMsg("Trying to link invalid 'this' to a Java object");
throw NativeScriptException(errMsg);
}
auto isolate = Isolate::GetCurrent();
DEBUG_WRITE("Linking js object: %d and java instance id: %d", object->GetIdentityHash(), javaObjectID);
auto jsInstanceInfo = new JSInstanceInfo();
jsInstanceInfo->JavaObjectID = javaObjectID;
jsInstanceInfo->clazz = clazz;
auto objectHandle = new Persistent<Object>(isolate, object);
auto state = new ObjectWeakCallbackState(this, jsInstanceInfo, objectHandle);
objectHandle->SetWeak(state, JSObjectWeakCallbackStatic);
auto jsInfoIdx = static_cast<int>(MetadataNodeKeys::JsInfo);
bool alreadyLinked = !object->GetInternalField(jsInfoIdx)->IsUndefined();
//TODO: fail if alreadyLinked is true?
auto jsInfo = External::New(isolate, jsInstanceInfo);
object->SetInternalField(jsInfoIdx, jsInfo);
idToObject.insert(make_pair(javaObjectID, objectHandle));
}
示例8:
Handle<Value> BGJSView::startJS(const char* fnName, const char* configJson, Handle<Value> uiObj, long configId) {
HandleScope scope;
Handle<Value> config;
if (configJson) {
config = String::New(configJson);
} else {
config = v8::Undefined();
}
// bgjsgl->Set(String::New("log"), FunctionTemplate::New(BGJSGLModule::log));
Local<Object> objInstance = this->jsViewOT->NewInstance();
objInstance->SetInternalField(0, External::New(this));
// Local<Object> instance = bgjsglft->GetFunction()->NewInstance();
this->_jsObj = Persistent<Object>::New(objInstance);
Handle<Value> argv[4] = { uiObj, this->_jsObj, config, Number::New(configId) };
Handle<Value> res = this->_jsContext->callFunction(_jsContext->_context->Global(), fnName, 4,
argv);
if (res->IsNumber()) {
_contentObj = res->ToNumber()->Value();
#ifdef DEBUG
LOGD ("startJS return id %d", _contentObj);
#endif
} else {
LOGI ("Did not receive a return id from startJS");
}
return scope.Close(res);
}
示例9: handleScope
// Wraps 'this' in a Javascript object.
Handle<Object> JsContext::wrap() {
// Handle scope for temporary handles.
EscapableHandleScope handleScope(fGlobal->getIsolate());
// Fetch the template for creating JavaScript JsContext wrappers.
// It only has to be created once, which we do on demand.
if (gContextTemplate.IsEmpty()) {
Local<ObjectTemplate> localTemplate = ObjectTemplate::New();
// Add a field to store the pointer to a JsContext instance.
localTemplate->SetInternalFieldCount(1);
this->addAttributesAndMethods(localTemplate);
gContextTemplate.Reset(fGlobal->getIsolate(), localTemplate);
}
Handle<ObjectTemplate> templ =
Local<ObjectTemplate>::New(fGlobal->getIsolate(), gContextTemplate);
// Create an empty JsContext wrapper.
Local<Object> result = templ->NewInstance();
// Wrap the raw C++ pointer in an External so it can be referenced
// from within JavaScript.
Handle<External> contextPtr = External::New(fGlobal->getIsolate(), this);
// Store the context pointer in the JavaScript wrapper.
result->SetInternalField(0, contextPtr);
// Return the result through the current handle scope. Since each
// of these handles will go away when the handle scope is deleted
// we need to call Close to let one, the result, escape into the
// outer handle scope.
return handleScope.Escape(result);
}
示例10: NanScope
Image *Image::New(FIBITMAP* dib) {
NanScope();
Local<Value> arg = NanNew<Integer>(0);
Local<Object> obj = NanNew<FunctionTemplate>(constructor_template)->GetFunction()->NewInstance(1, &arg);
Image *image = ObjectWrap::Unwrap<Image>(obj);
int w,h,pitch;
FREE_IMAGE_TYPE type = FreeImage_GetImageType(dib);
obj->SetInternalField(0, NanNew<External>(dib));
obj->Set(NanNew<String>("width"), NanNew<Integer>(w=FreeImage_GetWidth(dib)));
obj->Set(NanNew<String>("height"), NanNew<Integer>(h=FreeImage_GetHeight(dib)));
obj->Set(NanNew<String>("bpp"), NanNew<Integer>((int)FreeImage_GetBPP(dib)));
obj->Set(NanNew<String>("pitch"), NanNew<Integer>(pitch=FreeImage_GetPitch(dib)));
obj->Set(NanNew<String>("type"), NanNew<Integer>(type));
obj->Set(NanNew<String>("redMask"), NanNew<Integer>((int)FreeImage_GetRedMask(dib)));
obj->Set(NanNew<String>("greenMask"), NanNew<Integer>((int)FreeImage_GetGreenMask(dib)));
obj->Set(NanNew<String>("blueMask"), NanNew<Integer>((int)FreeImage_GetBlueMask(dib)));
BYTE *bits = FreeImage_GetBits(dib);
obj->Set(NanNew<String>("buffer"), NanNewBufferHandle((char*) bits, h * pitch));
return image;
}
示例11: PointConstructor
// Defines a Point() JS Object
void PointConstructor( const FunctionCallbackInfo<v8::Value>& args )
{
//Locker lock;
HandleScope scope;
Handle<ObjectTemplate> t = v8::ObjectTemplate::New();
//The JavaScript point object only has 1 C++ object
t->SetInternalFieldCount(1);
// Create x and y members with starting values of 0
//t->Set(String::New("x"), Number::New(0));
t->SetAccessor(String::New("x"),
(AccessorGetterCallback)GetPointX,
(AccessorSetterCallback)SetPointX);
//t->Set(String::New("y"), Number::New(0));
t->SetAccessor(String::New("y"),
(AccessorGetterCallback)GetPointY,
(AccessorSetterCallback)SetPointY);
// Create a mul(number) function that scales the point
t->Set(String::New("mul"), FunctionTemplate::New(MulCallback));
// for use in the if statement
Point *p = NULL;
Local<Object> obj;
// If Point(x, y) ctor was passed in values assign them
if(!args[0].IsEmpty() && args[0]->IsNumber() &&
!args[1].IsEmpty() && args[1]->IsNumber()) {
//t->Set(String::New("x"), args[0]);
//t->Set(String::New("y"), args[1]);
p = new Point(args[0]->Int32Value(), args[1]->Int32Value());
obj = t->NewInstance();
obj->SetInternalField(0, External::New(p));
} else {
/**
* Wrap a point object
*/
p = new Point(0, 0);
obj = t->NewInstance();
obj->SetInternalField(0, External::New(p));
}
// Return this newly created object
args.GetReturnValue().Set(obj);
}
示例12: JSExceptionNoDevice
v8::Local<v8::Object>
JSZCluster::createInstance(v8::Isolate *isolate, const ExtAddress &extAddress, EndpointID endpointId,
ClusterID clusterId) {
if (!zDevices->exists(extAddress)) {
throw JSExceptionNoDevice(extAddress);
}
auto zDevice = zDevices->getDevice(extAddress);
NwkAddr nwkAddress = zDevice->getNwkAddr();
Key key(nwkAddress, endpointId, clusterId);
if (usedCluster.count(key) > 0) {
return Local<Object>::New(isolate, usedCluster[key].get<0>());
}
if (!zDevice->isEndpointPresents(endpointId)) {
throw JSExceptionNoEndpoint(extAddress, endpointId);
}
ZEndpoint zEndpoint = zDevice->getEndpoint(endpointId);
if (!zEndpoint.hasInCluster(clusterId)) {
throw JSExceptionNoInCluster(extAddress, endpointId, clusterId);
}
Local<ObjectTemplate> zClusterTemplate = Local<FunctionTemplate>::New(isolate,
functionTemplate)->InstanceTemplate();
Local<Object> zClusterInstance = zClusterTemplate->NewInstance();
zClusterInstance->SetInternalField(0, External::New(isolate, this));
std::shared_ptr<Cluster> cluster = clusterFactory->getCluster(clusterId, zigbeeDevice, endpointId,
zDevice->getNwkAddr());
zClusterInstance->SetInternalField(1, External::New(isolate, cluster.get()));
std::shared_ptr<ExtAddress> usedAddr = getPersistenceExtAddress(extAddress);
zClusterInstance->SetInternalField(2, External::New(isolate, usedAddr.get()));
Value value{};
value.get<0>().Reset(isolate, zClusterInstance);
boost::get<1>(value) = cluster;
usedCluster.insert({key, value});
return zClusterInstance;
}
示例13: makeLine
void makeLine(const v8::FunctionCallbackInfo<v8::Value>& args) {
if(args.Length() != 4) {
args.GetReturnValue().Set(Boolean::New(Isolate::GetCurrent(), false));
return;
}
Local<External> shapeManagerExternal = Local<External>::Cast(args.Callee()->Get(String::NewFromUtf8(Isolate::GetCurrent(), shapeManagerStr.c_str())));
ShapeManager2d* shapeManager = static_cast<ShapeManager2d*>(shapeManagerExternal->Value());
Point2d p1{args[0]->NumberValue(), args[1]->NumberValue()};
Point2d p2{args[2]->NumberValue(), args[3]->NumberValue()};
Local<Object> obj = initShape()->NewInstance();
unsigned int shape = shapeManager->makeLine(p1, p2);
obj->SetInternalField(0, shapeManagerExternal);
obj->SetInternalField(1, Integer::NewFromUnsigned(Isolate::GetCurrent(), shape));
args.GetReturnValue().Set(obj);
}
示例14: CloneLink
bool ObjectManager::CloneLink(const Local<Object>& src, const Local<Object>& dest)
{
auto jsInfo = GetJSInstanceInfo(src);
auto success = jsInfo != nullptr;
if (success)
{
auto jsInfoIdx = static_cast<int>(MetadataNodeKeys::JsInfo);
auto jsInfo = src->GetInternalField(jsInfoIdx);
dest->SetInternalField(jsInfoIdx, jsInfo);
}
return success;
}
示例15: scope
void CanvasRenderingContext2D::Create(const v8::FunctionCallbackInfo<v8::Value>& args)
{
auto isolate = args.GetIsolate();
HandleScope scope(isolate);
Local<ObjectTemplate> contextTemplate = ObjectTemplate::New(isolate);
contextTemplate->SetInternalFieldCount(1);
contextTemplate->Set(ConvertToV8String("__draw"), FunctionTemplate::New(isolate, &Draw));
contextTemplate->Set(ConvertToV8String("__sizeChanged"), FunctionTemplate::New(isolate, &SizeChanged));
contextTemplate->SetAccessor(ConvertToV8String("fillStyle"), &GetFillStyle, &SetFillStyle);
contextTemplate->SetAccessor(ConvertToV8String("strokeStyle"), &GetStrokeStyle, &SetStrokeStyle);
contextTemplate->Set(ConvertToV8String("arc"), FunctionTemplate::New(isolate, &Arc));
contextTemplate->Set(ConvertToV8String("beginPath"), FunctionTemplate::New(isolate, &BeginPath));
contextTemplate->Set(ConvertToV8String("bezierCurveTo"), FunctionTemplate::New(isolate, &BezierCurveTo));
contextTemplate->Set(ConvertToV8String("clearRect"), FunctionTemplate::New(isolate, &ClearRect));
contextTemplate->Set(ConvertToV8String("closePath"), FunctionTemplate::New(isolate, &ClosePath));
contextTemplate->Set(ConvertToV8String("drawImage"), FunctionTemplate::New(isolate, &DrawImage));
contextTemplate->Set(ConvertToV8String("fill"), FunctionTemplate::New(isolate, &Fill));
contextTemplate->Set(ConvertToV8String("fillRect"), FunctionTemplate::New(isolate, &FillRect));
contextTemplate->Set(ConvertToV8String("fillText"), FunctionTemplate::New(isolate, &FillText));
contextTemplate->Set(ConvertToV8String("getImageData"), FunctionTemplate::New(isolate, &GetImageData));
contextTemplate->Set(ConvertToV8String("lineTo"), FunctionTemplate::New(isolate, &LineTo));
contextTemplate->Set(ConvertToV8String("measureText"), FunctionTemplate::New(isolate, &MeasureText));
contextTemplate->Set(ConvertToV8String("moveTo"), FunctionTemplate::New(isolate, &MoveTo));
contextTemplate->Set(ConvertToV8String("quadraticCurveTo"), FunctionTemplate::New(isolate, &QuadraticCurveTo));
contextTemplate->Set(ConvertToV8String("restore"), FunctionTemplate::New(isolate, &Restore));
contextTemplate->Set(ConvertToV8String("rotate"), FunctionTemplate::New(isolate, &Rotate));
contextTemplate->Set(ConvertToV8String("save"), FunctionTemplate::New(isolate, &Save));
contextTemplate->Set(ConvertToV8String("stroke"), FunctionTemplate::New(isolate, &Stroke));
contextTemplate->Set(ConvertToV8String("translate"), FunctionTemplate::New(isolate, &Translate));
Local<Object> newContext = contextTemplate->NewInstance();
newContext->ForceSet(ConvertToV8String("canvas"), args[0]);
newContext->ForceSet(ConvertToV8String("__kind"), ConvertToV8String("2d"));
auto nativeContext = new CanvasRenderingContext2D();
newContext->SetInternalField(0, External::New(isolate, nativeContext));
Persistent<Object> persistentHandle(isolate, newContext);
persistentHandle.SetWeak(nativeContext, &Deallocate);
args.GetReturnValue().Set(newContext);
}