Пример #1
0
BSONObj v8ToMongo( v8::Handle<v8::Object> o ){
    BSONObjBuilder b;

    v8::Handle<v8::String> idName = String::New( "_id" );
    if ( o->HasRealNamedProperty( idName ) ){
        v8ToMongoElement( b , idName , "_id" , o->Get( idName ) );
    }
    
    Local<v8::Array> names = o->GetPropertyNames();
    for ( unsigned int i=0; i<names->Length(); i++ ){
        v8::Local<v8::String> name = names->Get(v8::Integer::New(i) )->ToString();

        if ( o->GetPrototype()->IsObject() &&
             o->GetPrototype()->ToObject()->HasRealNamedProperty( name ) )
            continue;
        
        v8::Local<v8::Value> value = o->Get( name );
        
        const string sname = toSTLString( name );
        if ( sname == "_id" )
            continue;

        v8ToMongoElement( b , name , sname , value );
    }
    return b.obj();
}
Пример #2
0
bool copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcArray, uint32_t length, uint32_t offset, v8::Isolate* isolate)
{
    v8::Handle<v8::Value> prototype_value = destArray->GetPrototype();
    if (prototype_value.IsEmpty() || !prototype_value->IsObject())
        return false;
    v8::Handle<v8::Object> prototype = prototype_value.As<v8::Object>();
    v8::Handle<v8::Value> value = getHiddenCopyMethod(prototype);
    if (value.IsEmpty())
        value = installHiddenCopyMethod(prototype);
    if (value.IsEmpty() || !value->IsFunction())
        return false;
    v8::Handle<v8::Function> copy_method = value.As<v8::Function>();
    v8::Handle<v8::Value> arguments[3];
    arguments[0] = srcArray;
    arguments[1] = v8::Uint32::New(length);
    arguments[2] = v8::Uint32::New(offset);
    copy_method->Call(destArray, 3, arguments);
    return true;
}
Пример #3
0
bool copyElements(v8::Handle<v8::Object> destArray, v8::Handle<v8::Object> srcArray, uint32_t length, uint32_t offset, v8::Isolate* isolate)
{
    v8::Handle<v8::Value> prototype_value = destArray->GetPrototype();
    if (prototype_value.IsEmpty() || !prototype_value->IsObject())
        return false;
    v8::Handle<v8::Object> prototype = prototype_value.As<v8::Object>();
    v8::Handle<v8::Value> value = prototype->GetHiddenValue(V8HiddenPropertyName::typedArrayHiddenCopyMethod());
    if (value.IsEmpty()) {
        String source(reinterpret_cast<const char*>(V8ArrayBufferViewCustomScript_js), sizeof(V8ArrayBufferViewCustomScript_js));
        value = V8ScriptRunner::compileAndRunInternalScript(v8String(source, isolate), isolate);
        prototype->SetHiddenValue(V8HiddenPropertyName::typedArrayHiddenCopyMethod(), value);
    }
    if (value.IsEmpty() || !value->IsFunction())
        return false;
    v8::Handle<v8::Function> copy_method = value.As<v8::Function>();
    v8::Handle<v8::Value> arguments[3] = { srcArray, v8::Uint32::New(length), v8::Uint32::New(offset) };
    V8ScriptRunner::callInternalFunction(copy_method, destArray, WTF_ARRAY_LENGTH(arguments), arguments, isolate);
    return true;
}
Пример #4
0
static void checkDocumentWrapper(v8::Handle<v8::Object> wrapper, Document* document)
{
    ASSERT(V8Document::toNative(wrapper) == document);
    ASSERT(!document->isHTMLDocument() || (V8Document::toNative(v8::Handle<v8::Object>::Cast(wrapper->GetPrototype())) == document));
}