本文整理汇总了C++中Local::InternalFieldCount方法的典型用法代码示例。如果您正苦于以下问题:C++ Local::InternalFieldCount方法的具体用法?C++ Local::InternalFieldCount怎么用?C++ Local::InternalFieldCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Local
的用法示例。
在下文中一共展示了Local::InternalFieldCount方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wrap
void JavaObject::wrap(Isolate* isolate, Local<Object> jsObject)
{
ASSERT(persistent().IsEmpty());
ASSERT(jsObject->InternalFieldCount() > 0);
jsObject->SetAlignedPointerInInternalField(0, this);
persistent().Reset(isolate, jsObject);
}
示例2: 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));
}
示例3: Exception
void *ScriptObject::extractHolder(const Arguments &args)
{
HandleScope handleScope;
// Extract first internal field from Argument's holder object
Local<Object> holderObject = args.Holder();
if (holderObject->InternalFieldCount() < 1)
throw bit::Exception("No internal fields found in holder object");
Local<Value> holderValue = holderObject->GetInternalField(0);
if (holderValue.IsEmpty())
throw bit::Exception("Internal field could not be extracted from object");
if (!holderValue->IsExternal())
throw bit::Exception("The first field of holder object is not an ExternalObject");
// Extract void pointer
void *holderPointer = External::Unwrap(holderValue);
if (holderPointer == NULL)
throw bit::Exception("Extracted pointer is null");
return holderPointer;
}
示例4:
void* Get<void*> (Handle<Value> value) {
void *ptr = NULL;
if (value->IsObject()) {
Local<Object> object = value->ToObject();
if (object->InternalFieldCount()) {
ptr = object->GetPointerFromInternalField(0);
}
}
return ptr;
}
示例5: assert
void
encodeObjectID(bson_buffer *bb, const char *name, const Local<Value> element) {
// get at the delicious wrapped object centre
Local<Object> obj = element->ToObject();
assert(!obj.IsEmpty());
assert(obj->InternalFieldCount() > 0);
ObjectID *o = static_cast<ObjectID*>(Handle<External>::Cast(
obj->GetInternalField(0))->Value());
bson_oid_t oid;
char oid_hex[25];
o->str(oid_hex);
bson_oid_from_string(&oid, oid_hex);
bson_append_oid(bb, name, &oid);
}
示例6: jserror
jsvalue JsEngine::ErrorFromV8(TryCatch& trycatch)
{
jsvalue v;
HandleScope scope;
Local<Value> exception = trycatch.Exception();
v.type = JSVALUE_TYPE_UNKNOWN_ERROR;
v.value.str = 0;
v.length = 0;
// If this is a managed exception we need to place its ID inside the jsvalue
// and set the type JSVALUE_TYPE_MANAGED_ERROR to make sure the CLR side will
// throw on it.
if (exception->IsObject()) {
Local<Object> obj = Local<Object>::Cast(exception);
if (obj->InternalFieldCount() == 1) {
Local<External> wrap = Local<External>::Cast(obj->GetInternalField(0));
ManagedRef* ref = (ManagedRef*)wrap->Value();
v.type = JSVALUE_TYPE_MANAGED_ERROR;
v.length = ref->Id();
return v;
}
}
jserror *error = new jserror();
memset(error, 0, sizeof(jserror));
Local<Message> message = trycatch.Message();
if (!message.IsEmpty()) {
error->line = message->GetLineNumber();
error->column = message->GetStartColumn();
error->resource = AnyFromV8(message->GetScriptResourceName());
error->message = AnyFromV8(message->Get());
}
if (exception->IsObject()) {
Local<Object> obj2 = Local<Object>::Cast(exception);
error->type = AnyFromV8(obj2->GetConstructorName());
}
error->exception = AnyFromV8(exception);
v.type = JSVALUE_TYPE_ERROR;
v.value.ptr = error;
return v;
}
示例7: DisposeOpenCLObject
void DisposeOpenCLObject (Persistent<Value> value, void* release) {
if (release && value->IsObject()) {
Local<Object> object = value->ToObject();
if (object->InternalFieldCount()) {
void *ptr = object->GetPointerFromInternalField(0);
int32_t (CALL *clRelease) (void* smth);
*(void**) &clRelease = release;
clRelease(ptr); // Returned value is omitted. Check when debugging.
}
}
value.Dispose();
value.Clear();
}
示例8: isValueObject
Handle<Value> isValueObject(const Arguments &args) {
HandleScope scope;
bool answer = false;
Handle<Value> v = args[0];
if(v->IsObject()) {
Local<Object> o = v->ToObject();
if(o->InternalFieldCount() == 2) {
Envelope * n = (Envelope *) o->GetPointerFromInternalField(0);
if(n == & nroEnvelope) {
answer = true;
}
}
}
return scope.Close(Boolean::New(answer));
}
示例9: jsCreate
void JsVlcVideo::jsCreate( const v8::FunctionCallbackInfo<v8::Value>& args )
{
using namespace v8;
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope( isolate );
Local<Object> thisObject = args.Holder();
if( args.IsConstructCall() && thisObject->InternalFieldCount() > 0 ) {
JsVlcPlayer* jsPlayer =
ObjectWrap::Unwrap<JsVlcPlayer>( Handle<Object>::Cast( args[0] ) );
if( jsPlayer ) {
JsVlcVideo* jsPlaylist = new JsVlcVideo( thisObject, jsPlayer );
args.GetReturnValue().Set( thisObject );
}
} else {
Local<Function> constructor =
Local<Function>::New( isolate, _jsConstructor );
Local<Value> argv[] = { args[0] };
args.GetReturnValue().Set(
constructor->NewInstance( sizeof( argv ) / sizeof( argv[0] ), argv ) );
}
}
示例10: if
void v8ToMongoElement( BSONObjBuilder & b , v8::Handle<v8::String> name , const string sname , v8::Handle<v8::Value> value ){
if ( value->IsString() ){
b.append( sname.c_str() , toSTLString( value ).c_str() );
return;
}
if ( value->IsFunction() ){
b.appendCode( sname.c_str() , toSTLString( value ).c_str() );
return;
}
if ( value->IsNumber() ){
if ( value->IsInt32() )
b.append( sname.c_str(), int( value->ToInt32()->Value() ) );
else
b.append( sname.c_str() , value->ToNumber()->Value() );
return;
}
if ( value->IsArray() ){
BSONObj sub = v8ToMongo( value->ToObject() );
b.appendArray( sname.c_str() , sub );
return;
}
if ( value->IsDate() ){
b.appendDate( sname.c_str() , Date_t(v8::Date::Cast( *value )->NumberValue()) );
return;
}
if ( value->IsExternal() )
return;
if ( value->IsObject() ){
// The user could potentially modify the fields of these special objects,
// wreaking havoc when we attempt to reinterpret them. Not doing any validation
// for now...
Local< v8::Object > obj = value->ToObject();
if ( obj->InternalFieldCount() && obj->GetInternalField( 0 )->IsNumber() ) {
switch( obj->GetInternalField( 0 )->ToInt32()->Value() ) { // NOTE Uint32's Value() gave me a linking error, so going with this instead
case Timestamp:
b.appendTimestamp( sname.c_str(),
Date_t( v8::Date::Cast( *obj->Get( v8::String::New( "time" ) ) )->NumberValue() ),
obj->Get( v8::String::New( "i" ) )->ToInt32()->Value() );
return;
case MinKey:
b.appendMinKey( sname.c_str() );
return;
case MaxKey:
b.appendMaxKey( sname.c_str() );
return;
default:
assert( "invalid internal field" == 0 );
}
}
string s = toSTLString( value );
if ( s.size() && s[0] == '/' ){
s = s.substr( 1 );
string r = s.substr( 0 , s.rfind( "/" ) );
string o = s.substr( s.rfind( "/" ) + 1 );
b.appendRegex( sname.c_str() , r.c_str() , o.c_str() );
}
else if ( value->ToObject()->GetPrototype()->IsObject() &&
value->ToObject()->GetPrototype()->ToObject()->HasRealNamedProperty( v8::String::New( "isObjectId" ) ) ){
OID oid;
oid.init( toSTLString( value ) );
b.appendOID( sname.c_str() , &oid );
}
else if ( !value->ToObject()->GetHiddenValue( v8::String::New( "__NumberLong" ) ).IsEmpty() ) {
// TODO might be nice to potentially speed this up with an indexed internal
// field, but I don't yet know how to use an ObjectTemplate with a
// constructor.
unsigned long long val =
( (unsigned long long)( value->ToObject()->Get( v8::String::New( "top" ) )->ToInt32()->Value() ) << 32 ) +
(unsigned)( value->ToObject()->Get( v8::String::New( "bottom" ) )->ToInt32()->Value() );
b.append( sname.c_str(), (long long)val );
}
else if ( !value->ToObject()->GetHiddenValue( v8::String::New( "__DBPointer" ) ).IsEmpty() ) {
OID oid;
oid.init( toSTLString( value->ToObject()->Get( v8::String::New( "id" ) ) ) );
string ns = toSTLString( value->ToObject()->Get( v8::String::New( "ns" ) ) );
b.appendDBRef( sname.c_str(), ns.c_str(), oid );
}
else if ( !value->ToObject()->GetHiddenValue( v8::String::New( "__BinData" ) ).IsEmpty() ) {
int len = obj->Get( v8::String::New( "len" ) )->ToInt32()->Value();
v8::String::Utf8Value data( obj->Get( v8::String::New( "data" ) ) );
const char *dataArray = *data;
assert( data.length() == len );
b.appendBinData( sname.c_str(),
len,
mongo::BinDataType( obj->Get( v8::String::New( "type" ) )->ToInt32()->Value() ),
dataArray );
} else {
BSONObj sub = v8ToMongo( value->ToObject() );
b.append( sname.c_str() , sub );
}
return;
}
//.........这里部分代码省略.........