예제 #1
0
static void installV8TestInterface3Template(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
{
    functionTemplate->ReadOnlyPrototype();

    v8::Local<v8::Signature> defaultSignature;
    defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterface3", v8::Local<v8::FunctionTemplate>(), V8TestInterface3::internalFieldCount,
        0, 0,
        0, 0,
        0, 0,
        isolate);
    v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate();
    ALLOW_UNUSED_LOCAL(instanceTemplate);
    v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate();
    ALLOW_UNUSED_LOCAL(prototypeTemplate);
    functionTemplate->InstanceTemplate()->SetIndexedPropertyHandler(TestInterface3V8Internal::indexedPropertyGetterCallback, TestInterface3V8Internal::indexedPropertySetterCallback, 0, TestInterface3V8Internal::indexedPropertyDeleterCallback, indexedPropertyEnumerator<TestInterface3>);
    functionTemplate->InstanceTemplate()->SetNamedPropertyHandler(TestInterface3V8Internal::namedPropertyGetterCallback, TestInterface3V8Internal::namedPropertySetterCallback, TestInterface3V8Internal::namedPropertyQueryCallback, TestInterface3V8Internal::namedPropertyDeleterCallback, TestInterface3V8Internal::namedPropertyEnumeratorCallback);

    // Custom toString template
    functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
}
static void installV8TestInterfaceGarbageCollectedTemplate(v8::Handle<v8::FunctionTemplate> functionTemplate, v8::Isolate* isolate)
{
    functionTemplate->ReadOnlyPrototype();

    v8::Local<v8::Signature> defaultSignature;
    defaultSignature = V8DOMConfiguration::installDOMClassTemplate(functionTemplate, "TestInterfaceGarbageCollected", V8EventTarget::domTemplate(isolate), V8TestInterfaceGarbageCollected::internalFieldCount,
        V8TestInterfaceGarbageCollectedAttributes, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedAttributes),
        0, 0,
        V8TestInterfaceGarbageCollectedMethods, WTF_ARRAY_LENGTH(V8TestInterfaceGarbageCollectedMethods),
        isolate);
    functionTemplate->SetCallHandler(V8TestInterfaceGarbageCollected::constructorCallback);
    functionTemplate->SetLength(1);
    v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceTemplate();
    ALLOW_UNUSED_LOCAL(instanceTemplate);
    v8::Local<v8::ObjectTemplate> prototypeTemplate = functionTemplate->PrototypeTemplate();
    ALLOW_UNUSED_LOCAL(prototypeTemplate);

    // Custom toString template
    functionTemplate->Set(v8AtomicString(isolate, "toString"), V8PerIsolateData::from(isolate)->toStringTemplate());
}
uint32_t toUInt32(v8::Handle<v8::Value> value, bool& ok)
{
    ok = true;

    // Fast case. The value is already a 32-bit unsigned integer.
    if (value->IsUint32())
        return value->Uint32Value();

    if (value->IsInt32()) {
        int32_t result = value->Int32Value();
        if (result >= 0)
            return result;
    }

    // Can the value be converted to a number?
    v8::Local<v8::Number> numberObject = value->ToNumber();
    if (numberObject.IsEmpty()) {
        ok = false;
        return 0;
    }

    // Does the value convert to nan or to an infinity?
    double numberValue = numberObject->Value();
    if (isnan(numberValue) || isinf(numberValue)) {
        ok = false;
        return 0;
    }

    // Can the value be converted to a 32-bit unsigned integer?
    v8::Local<v8::Uint32> uintValue = value->ToUint32();
    if (uintValue.IsEmpty()) {
        ok = false;
        return 0;
    }

    return uintValue->Value();
}
예제 #4
0
StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode external)
{
    {
        // This portion of this function is very hot in certain Dromeao benchmarks.
        v8::String::Encoding encoding;
        v8::String::ExternalStringResourceBase* resource = v8String->GetExternalStringResourceBase(&encoding);
        if (LIKELY(!!resource)) {
            WebCoreStringResourceBase* base;
            if (encoding == v8::String::ONE_BYTE_ENCODING)
                base = static_cast<WebCoreStringResource8*>(resource);
            else
                base = static_cast<WebCoreStringResource16*>(resource);
            return StringTraits<StringType>::fromStringResource(base);
        }
    }

    int length = v8String->Length();
    if (UNLIKELY(!length))
        return StringType("");

    bool oneByte = v8String->ContainsOnlyOneByte();
    StringType result(oneByte ? StringTraits<StringType>::template fromV8String<V8StringOneByteTrait>(v8String, length) : StringTraits<StringType>::template fromV8String<V8StringTwoBytesTrait>(v8String, length));

    if (external != Externalize || !v8String->CanMakeExternal())
        return result;

    if (result.is8Bit()) {
        WebCoreStringResource8* stringResource = new WebCoreStringResource8(result);
        if (UNLIKELY(!v8String->MakeExternal(stringResource)))
            delete stringResource;
    } else {
        WebCoreStringResource16* stringResource = new WebCoreStringResource16(result);
        if (UNLIKELY(!v8String->MakeExternal(stringResource)))
            delete stringResource;
    }
    return result;
}
예제 #5
0
void InitAll(v8::Handle<v8::Object> exports)
{
    exports->Set(NanNew<v8::String>("foo"),
                 NanNew<v8::FunctionTemplate>(Foo)->GetFunction());
}
static AtomicString v8NonStringValueToAtomicWebCoreString(v8::Handle<v8::Value> object)
{
    ASSERT(!object->IsString());
    return AtomicString(v8NonStringValueToWebCoreString(object));
}
예제 #7
0
void JsVlcPlayer::initJsApi( const v8::Handle<v8::Object>& exports )
{
    node::AtExit( [] ( void* ) { JsVlcPlayer::closeAll(); } );

    JsVlcInput::initJsApi();
    JsVlcAudio::initJsApi();
    JsVlcVideo::initJsApi();
    JsVlcSubtitles::initJsApi();
    JsVlcPlaylist::initJsApi();

    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope( isolate );

    Local<FunctionTemplate> constructorTemplate = FunctionTemplate::New( isolate, jsCreate );
    constructorTemplate->SetClassName( String::NewFromUtf8( isolate, "VlcPlayer", v8::String::kInternalizedString ) );

    Local<ObjectTemplate> protoTemplate = constructorTemplate->PrototypeTemplate();
    Local<ObjectTemplate> instanceTemplate = constructorTemplate->InstanceTemplate();
    instanceTemplate->SetInternalFieldCount( 1 );

    protoTemplate->Set( String::NewFromUtf8( isolate, "RV32", v8::String::kInternalizedString ),
                        Integer::New( isolate, static_cast<int>( PixelFormat::RV32 ) ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "I420", v8::String::kInternalizedString ),
                        Integer::New( isolate, static_cast<int>( PixelFormat::I420 ) ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );

    protoTemplate->Set( String::NewFromUtf8( isolate, "NothingSpecial", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_NothingSpecial ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Opening", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Opening ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Buffering", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Buffering ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Playing", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Playing ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Paused", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Paused ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Stopped", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Stopped ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Ended", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Ended ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );
    protoTemplate->Set( String::NewFromUtf8( isolate, "Error", v8::String::kInternalizedString ),
                        Integer::New( isolate, libvlc_Error ),
                        static_cast<v8::PropertyAttribute>( ReadOnly | DontDelete ) );

    SET_CALLBACK_PROPERTY( instanceTemplate, "onFrameSetup", CB_FrameSetup );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onFrameReady", CB_FrameReady );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onFrameCleanup", CB_FrameCleanup );

    SET_CALLBACK_PROPERTY( instanceTemplate, "onMediaChanged", CB_MediaPlayerMediaChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onNothingSpecial", CB_MediaPlayerNothingSpecial );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onOpening", CB_MediaPlayerOpening );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onBuffering", CB_MediaPlayerBuffering );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onPlaying", CB_MediaPlayerPlaying );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onPaused", CB_MediaPlayerPaused );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onForward", CB_MediaPlayerForward );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onBackward", CB_MediaPlayerBackward );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onEncounteredError", CB_MediaPlayerEncounteredError );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onEndReached", CB_MediaPlayerEndReached );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onStopped", CB_MediaPlayerStopped );

    SET_CALLBACK_PROPERTY( instanceTemplate, "onTimeChanged", CB_MediaPlayerTimeChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onPositionChanged", CB_MediaPlayerPositionChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onSeekableChanged", CB_MediaPlayerSeekableChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onPausableChanged", CB_MediaPlayerPausableChanged );
    SET_CALLBACK_PROPERTY( instanceTemplate, "onLengthChanged", CB_MediaPlayerLengthChanged );

    SET_RO_PROPERTY( instanceTemplate, "playing", &JsVlcPlayer::playing );
    SET_RO_PROPERTY( instanceTemplate, "length", &JsVlcPlayer::length );
    SET_RO_PROPERTY( instanceTemplate, "state", &JsVlcPlayer::state );

    SET_RO_PROPERTY( instanceTemplate, "input", &JsVlcPlayer::input );
    SET_RO_PROPERTY( instanceTemplate, "audio", &JsVlcPlayer::audio );
    SET_RO_PROPERTY( instanceTemplate, "video", &JsVlcPlayer::video );
    SET_RO_PROPERTY( instanceTemplate, "subtitles", &JsVlcPlayer::subtitles );
    SET_RO_PROPERTY( instanceTemplate, "playlist", &JsVlcPlayer::playlist );

    SET_RO_PROPERTY( instanceTemplate, "videoFrame", &JsVlcPlayer::getVideoFrame );
    SET_RO_PROPERTY( instanceTemplate, "events", &JsVlcPlayer::getEventEmitter );

    SET_RW_PROPERTY( instanceTemplate, "pixelFormat", &JsVlcPlayer::pixelFormat, &JsVlcPlayer::setPixelFormat );
    SET_RW_PROPERTY( instanceTemplate, "position", &JsVlcPlayer::position, &JsVlcPlayer::setPosition );
    SET_RW_PROPERTY( instanceTemplate, "time", &JsVlcPlayer::time, &JsVlcPlayer::setTime );
    SET_RW_PROPERTY( instanceTemplate, "volume", &JsVlcPlayer::volume, &JsVlcPlayer::setVolume );
    SET_RW_PROPERTY( instanceTemplate, "mute", &JsVlcPlayer::muted, &JsVlcPlayer::setMuted );

    NODE_SET_PROTOTYPE_METHOD( constructorTemplate, "play", jsPlay );
    SET_METHOD( constructorTemplate, "pause", &JsVlcPlayer::pause );
    SET_METHOD( constructorTemplate, "togglePause", &JsVlcPlayer::togglePause );
    SET_METHOD( constructorTemplate, "stop",  &JsVlcPlayer::stop );
    SET_METHOD( constructorTemplate, "toggleMute", &JsVlcPlayer::toggleMute );

    Local<Function> constructor = constructorTemplate->GetFunction();
    _jsConstructor.Reset( isolate, constructor );
    exports->Set( String::NewFromUtf8( isolate, "VlcPlayer", v8::String::kInternalizedString ), constructor );
    exports->Set( String::NewFromUtf8( isolate, "createPlayer", v8::String::kInternalizedString ), constructor );
}
예제 #8
0
void TRI_AddGlobalFunctionVocbase (v8::Handle<v8::Context> context,
                                   const char* const name,
                                   v8::Handle<v8::Function> func) {
  // all global functions are read-only
  context->Global()->Set(TRI_V8_SYMBOL(name), func, v8::ReadOnly);
}
예제 #9
0
namespace tut 
{
    static v8::Handle<v8::ObjectTemplate> global;
    static v8::HandleScope handle_scope;
    static v8::Handle<v8::Context> context;
    //local variables accessible inside script
    static char username[1024];
    static int x;
    struct try_javascript_try_v8_embeded_data
    {
        //get the value of x variable inside javascript
        static v8::Handle<v8::Value> XGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) {
            return  v8::Number::New(x);
        }

        //set the value of x variable inside javascript
        static void XSetter(v8::Local<v8::String> name,v8::Local<v8::Value> value,const v8::AccessorInfo& info) {
            x = value->Int32Value();
        }
        //get the value of username variable inside javascript
        static v8::Handle<v8::Value> userGetter(v8::Local<v8::String> name,const v8::AccessorInfo& info) {
            return v8::String::New((char*)&username,strlen((char*)&username));
        }

        //set the value of username variable inside javascript
        static void userSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value,const v8::AccessorInfo& info) {
            v8::Local<v8::String> s = value->ToString();
            s->WriteAscii((char*)&username);
        }

        //convert unsigned int to value
        static v8::Local<v8::Value> v8_uint32(unsigned int x) {
            return v8::Uint32::New(x);
        }
        // Add two numbers
        static v8::Handle<v8::Value> Plus(const v8::Arguments& args)
        {
            unsigned int A = args[0]->Uint32Value();
            unsigned int B = args[1]->Uint32Value();
            return v8_uint32(A +  B);
        }

        // The callback that is invoked by v8 whenever the JavaScript 'print'
        // function is called.  Prints its arguments on stdout separated by
        // spaces and ending with a newline.
        static v8::Handle<v8::Value> Print(const v8::Arguments& args) {
            bool first = true;
            for (int i = 0; i < args.Length(); i++)
            {
                v8::HandleScope handle_scope;
                if (first)
                {
                    first = false;
                }
                else
                {
                    printf(" ");
                }
                //convert the args[i] type to normal char* string
                v8::String::AsciiValue str(args[i]);
                printf("%s", *str);
            }
            printf("\n");
            //returning Undefined is the same as returning void...
            return v8::Undefined();
        }
        // Executes a string within the current v8 context.
        static bool ExecuteString(v8::Handle<v8::String> source,v8::Handle<v8::String> name) {
            //access global context within this scope
            v8::Context::Scope context_scope(context);
            //exception handler
            v8::TryCatch try_catch;
            //compile script to binary code - JIT
            v8::Handle<v8::Script> script = v8::Script::Compile(source, name);
            bool print_result = true;
            //check if we got problems on compilation
            if (script.IsEmpty()) {

                // Print errors that happened during compilation.
                v8::String::AsciiValue error(try_catch.Exception());
                printf("%s\n", *error);
                return false;
            }
            else
            {
                //no errors , let's continue
                v8::Handle<v8::Value> result = script->Run();

                //check if execution ended with errors
                if(result.IsEmpty()) {
                    // Print errors that happened during execution.
                    v8::String::AsciiValue error(try_catch.Exception());
                    printf("%s\n", *error);
                    return false;
                } else {
                    if (print_result && !result->IsUndefined()) {
                        // If all went well and the result wasn't undefined then print
                        // the returned value.
                        v8::String::AsciiValue str(result);
                        printf("script result [%s]\n", *str);
                    }
                    return true;
                }
            }
        }
    };
    typedef test_group<try_javascript_try_v8_embeded_data> TestGroup;
    TestGroup ThisTestGroup("try_javascript_try_v8_embeded_data");

    typedef TestGroup::object TestObject;

    template<> 
    template<> 
    void TestObject::test<1>() 
    {
        set_test_name("Try Google V8 Embedded Demo");

        // This sample is copied from codeproject.com
        // http://www.codeproject.com/Articles/29109/Using-V8-Google-s-Chrome-JavaScript-Virtual-Machine
        char *script = "print(\"begin script\");"
            "print(\"script executed by \"+user);"
            "if ( user == \"John Doe\"){"
            "print(\"\\tuser name is invalid. Changing name to Chuck Norris\");"
            "user = \"Chuck Norris\";}"
            "print(\"123 plus 27 = \" + plus(123,27));"
            "x = plus(3456789,6543211);"
            "print(\"end script\");";
        char *script_name = "internal_script";
        //convert the string with the script to a v8 string
        v8::Handle<v8::String> source =  v8::String::New(script, strlen(script));

        //each script name must be unique , for this demo I just run one embedded script, so the name can be fixed
        v8::Handle<v8::String> name = v8::String::New(script_name,strlen(script_name)); 
        // Create a template for the global object.
        global = v8::ObjectTemplate::New();

        //associates "plus" on script to the Plus function
        global->Set(v8::String::New("plus"), v8::FunctionTemplate::New(Plus));
        //associates "print" on script to the Print function
        global->Set(v8::String::New("print"), v8::FunctionTemplate::New(Print));

        //create accessor for string username
        global->SetAccessor(v8::String::New("user"),userGetter,userSetter);
        //create accessor for integer x
        global->SetAccessor(v8::String::New("x"), XGetter, XSetter);

        //create context for the script
        context = v8::Context::New(NULL, global);
        //fill username with something
        strcpy((char*)&username,"John Doe");

        //x initialization
        x=0;
        printf("################### BEFORE SCRIPT EXECUTION ###################\n");
        //simple JavaScript to test
        ExecuteString(source,name);

        //check if my username changed...
        if(strcmp(username,"John Doe")!=0) {
            printf("################### AFTER SCRIPT EXECUTION ###################\n");
            printf("Script changed my username to %s\n", (char*)&username);
            printf("x value after script [%d]\n",x);
        }
    }
}; 
예제 #10
0
static bool hasInternalField(v8::Handle<v8::Value> value)
{
    if (value.IsEmpty() || !value->IsObject())
        return false;
    return v8::Handle<v8::Object>::Cast(value)->InternalFieldCount();
}
예제 #11
0
void V8DOMConfiguration::batchConfigureCallbacks(v8::Handle<v8::ObjectTemplate> prototype, v8::Handle<v8::Signature> signature, v8::PropertyAttribute attributes, const BatchedCallback* callbacks, size_t callbackCount, v8::Isolate*)
{
    for (size_t i = 0; i < callbackCount; ++i)
        prototype->Set(v8::String::NewSymbol(callbacks[i].name), v8::FunctionTemplate::New(callbacks[i].callback, v8Undefined(), signature), attributes);
}
예제 #12
0
void Init (v8::Handle<v8::Object> target) {
  target->Set(
      NanNew<v8::String>("r")
    , NanNew<v8::FunctionTemplate>(ReturnString)->GetFunction()
  );
}
예제 #13
0
파일: returnvalue.cpp 프로젝트: 4ver/nan
void Init (v8::Handle<v8::Object> target) {
  target->Set(
      NanSymbol("r")
    , v8::FunctionTemplate::New(ReturnValue)->GetFunction()
  );
}
예제 #14
0
void JSVideoFrame::CreateTemplateDefaultFields(v8::Handle<v8::ObjectTemplate> templ) {
	templ->Set(JSPROP_NAME("getContext"), v8::FunctionTemplate::New(JSGetContext), JSPROP_READONLY);
	templ->Set(JSPROP_NAME("getSimpleContext"), v8::FunctionTemplate::New(JSGetSimpleContext), JSPROP_READONLY);
}
예제 #15
0
uint64 TNodeJsUtil::GetTmMSecs(v8::Handle<v8::Date>& Date) {
	return GetCppTimestamp(int64(Date->NumberValue()));
}
예제 #16
0
v8::Local<v8::Value> V8Proxy::runScript(v8::Handle<v8::Script> script, bool isInlineCode)
{
    if (script.IsEmpty())
        return notHandledByInterceptor();

    /// M: add for systrace
    TRACE_METHOD()
    V8GCController::checkMemoryUsage();
    // Compute the source string and prevent against infinite recursion.
    if (m_recursion >= kMaxRecursionDepth) {
        v8::Local<v8::String> code = v8ExternalString("throw RangeError('Recursion too deep')");
        // FIXME: Ideally, we should be able to re-use the origin of the
        // script passed to us as the argument instead of using an empty string
        // and 0 baseLine.
        script = compileScript(code, "", TextPosition0::minimumPosition());
    }

    if (handleOutOfMemory())
        ASSERT(script.IsEmpty());

    if (script.IsEmpty())
        return notHandledByInterceptor();

    // Save the previous value of the inlineCode flag and update the flag for
    // the duration of the script invocation.
    bool previousInlineCode = inlineCode();
    setInlineCode(isInlineCode);

    // Run the script and keep track of the current recursion depth.
    v8::Local<v8::Value> result;
    v8::TryCatch tryCatch;
    tryCatch.SetVerbose(true);
    {
        // See comment in V8Proxy::callFunction.
        m_frame->keepAlive();

        m_recursion++;
        result = script->Run();
        m_recursion--;
    }

    // Release the storage mutex if applicable.
    didLeaveScriptContext();

    if (handleOutOfMemory())
        ASSERT(result.IsEmpty());

    // Handle V8 internal error situation (Out-of-memory).
    if (tryCatch.HasCaught()) {
        ASSERT(result.IsEmpty());
        return notHandledByInterceptor();
    }

    if (result.IsEmpty())
        return notHandledByInterceptor();

    // Restore inlineCode flag.
    setInlineCode(previousInlineCode);

    if (v8::V8::IsDead())
        handleFatalErrorInV8();

    return result;
}
예제 #17
0
///////////////////////////////
// QMiner-JavaScript-Stream-Aggr
TNodeJsStreamAggr::TNodeJsStreamAggr(TWPt<TQm::TBase> _Base, const TStr& _AggrNm, v8::Handle<v8::Object> TriggerVal) : TStreamAggr(_Base, _AggrNm) {
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
	v8::HandleScope HandleScope(Isolate);
	// Every stream aggregate should implement these two
	QmAssertR(TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "onAdd")), "TNodeJsStreamAggr constructor, name: " + _AggrNm + ", type: javaScript. Missing onAdd callback. Possible reason: type of the aggregate was not specified and it defaulted to javaScript.");
	QmAssertR(TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "saveJson")), "TNodeJsStreamAggr constructor, name: " + _AggrNm + ", type: javaScript. Missing saveJson callback. Possible reason: type of the aggregate was not specified and it defaulted to javaScript.");

	v8::Handle<v8::Value> _OnAddFun = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "onAdd"));
	QmAssert(_OnAddFun->IsFunction());
	OnAddFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_OnAddFun));

	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "onUpdate"))) {
		v8::Handle<v8::Value> _OnUpdateFun = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "onUpdate"));
		QmAssert(_OnUpdateFun->IsFunction());
		OnUpdateFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_OnUpdateFun));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "onDelete"))) {
		v8::Handle<v8::Value> _OnDeleteFun = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "onDelete"));
		QmAssert(_OnDeleteFun->IsFunction());
		OnDeleteFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_OnDeleteFun));
	}

	v8::Handle<v8::Value> _SaveJsonFun = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "saveJson"));
	QmAssert(_SaveJsonFun->IsFunction());
	SaveJsonFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_SaveJsonFun));

	// StreamAggr::_Save
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "save"))) {
		v8::Handle<v8::Value> _Save = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "save"));
		QmAssert(_Save->IsFunction());
		SaveFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_Save));
	}

	// StreamAggr::_Load
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "load"))) {
		v8::Handle<v8::Value> _Load = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "load"));
		QmAssert(_Load->IsFunction());
		LoadFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_Load));
	}

	// IInt
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getInt"))) {
		v8::Handle<v8::Value> _GetInt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getInt"));
		QmAssert(_GetInt->IsFunction());
		GetIntFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetInt));
	}
	// IFlt 
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getFlt"))) {
		v8::Handle<v8::Value> _GetFlt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getFlt"));
		QmAssert(_GetFlt->IsFunction());
		GetFltFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetFlt));
	}
	// ITm 
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getTm"))) {
		v8::Handle<v8::Value> _GetTm = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getTm"));
		QmAssert(_GetTm->IsFunction());
		GetTmMSecsFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetTm));
	}
	// IFltTmIO 
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getInFlt"))) {
		v8::Handle<v8::Value> _GetInFlt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getInFlt"));
		QmAssert(_GetInFlt->IsFunction());
		GetInFltFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetInFlt));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getInTm"))) {
		v8::Handle<v8::Value> _GetInTm = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getInTm"));
		QmAssert(_GetInTm->IsFunction());
		GetInTmMSecsFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetInTm));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getOutFltV"))) {
		v8::Handle<v8::Value> _GetOutFltV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getOutFltV"));
		QmAssert(_GetOutFltV->IsFunction());
		GetOutFltVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetOutFltV));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getOutTmV"))) {
		v8::Handle<v8::Value> _GetOutTmV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getOutTmV"));
		QmAssert(_GetOutTmV->IsFunction());
		GetOutTmMSecsVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetOutTmV));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getN"))) {
		v8::Handle<v8::Value> _GetN = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getN"));
		QmAssert(_GetN->IsFunction());
		GetNFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetN));
	}
	// IFltVec
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getFltLen"))) {
		v8::Handle<v8::Value> _GetFltLen = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getFltLen"));
		QmAssert(_GetFltLen->IsFunction());
		GetFltLenFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetFltLen));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getFltAt"))) {
		v8::Handle<v8::Value> _GetFltAt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getFltAt"));
		QmAssert(_GetFltAt->IsFunction());
		GetFltAtFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetFltAt));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getFltV"))) {
		v8::Handle<v8::Value> _GetFltV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getFltV"));
		QmAssert(_GetFltV->IsFunction());
		GetFltVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetFltV));
	}
	// INmFlt 
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "isNmFlt"))) {
		v8::Handle<v8::Value> _IsNmFlt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "isNmFlt"));
		QmAssert(_IsNmFlt->IsFunction());
		IsNmFltFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_IsNmFlt));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getNmFlt"))) {
		v8::Handle<v8::Value> _GetNmFlt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getNmFlt"));
		QmAssert(_GetNmFlt->IsFunction());
		GetNmFltFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetNmFlt));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getNmFltV"))) {
		v8::Handle<v8::Value> _GetNmFltV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getNmFltV"));
		QmAssert(_GetNmFltV->IsFunction());
		GetNmFltVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetNmFltV));
	}
	// INmInt
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "isNm"))) {
		v8::Handle<v8::Value> _IsNm = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "isNm"));
		QmAssert(_IsNm->IsFunction());
		IsNmFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_IsNm));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getNmInt"))) {
		v8::Handle<v8::Value> _GetNmInt = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getNmInt"));
		QmAssert(_GetNmInt->IsFunction());
		GetNmIntFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetNmInt));
	}
	if (TriggerVal->Has(v8::String::NewFromUtf8(Isolate, "getNmIntV"))) {
		v8::Handle<v8::Value> _GetNmIntV = TriggerVal->Get(v8::String::NewFromUtf8(Isolate, "getNmIntV"));
		QmAssert(_GetNmIntV->IsFunction());
		GetNmIntVFun.Reset(Isolate, v8::Handle<v8::Function>::Cast(_GetNmIntV));
	}
}
예제 #18
0
void ArrayType::LongSet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index, v8::Handle<v8::Value> elt) {
  jniEnv->CallVoidMethod(ob, arr->setElement, index, (jlong)elt->IntegerValue());
}
예제 #19
0
void TRI_AddGlobalFunctionVocbase (v8::Handle<v8::Context> context,
                                   const char* const name,
                                   v8::Handle<v8::Value>(*func)(v8::Arguments const&)) {
  // all global functions are read-only
  context->Global()->Set(TRI_V8_SYMBOL(name), v8::FunctionTemplate::New(func)->GetFunction(), v8::ReadOnly);
}
예제 #20
0
void ArrayType::DoubleSet(ArrayType *arr, JNIEnv *jniEnv, jobject ob, uint32_t index, v8::Handle<v8::Value> elt) {
  jniEnv->CallVoidMethod(ob, arr->setElement, index, (jdouble)elt->NumberValue());
}
예제 #21
0
void TRI_AddGlobalVariableVocbase (v8::Handle<v8::Context> context,
                                   const char* const name,
                                   v8::Handle<v8::Value> value) {
  // all global functions are read-only
  context->Global()->Set(TRI_V8_SYMBOL(name), value, v8::ReadOnly);
}
예제 #22
0
float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
{
    V8TRYCATCH_EXCEPTION_RETURN(v8::Local<v8::Number>, numberObject, value->ToNumber(), exceptionState, 0);
    return numberObject->NumberValue();
}
예제 #23
0
static bool isLegacyTargetOriginDesignation(v8::Handle<v8::Value> value)
{
    if (value->IsString() || value->IsStringObject())
        return true;
    return false;
}
예제 #24
0
v8::Local<v8::Value> getHiddenValue(v8::Isolate* isolate, v8::Handle<v8::Object> object, v8::Handle<v8::String> key)
{
    return object->GetHiddenValue(key);
}
AtomicString toWebCoreAtomicString(v8::Handle<v8::Value> value)
{
    if (value->IsString())
        return v8StringToWebCoreString<AtomicString>(v8::Handle<v8::String>::Cast(value), Externalize);
    return v8NonStringValueToAtomicWebCoreString(value);
}
예제 #26
0
bool setHiddenValue(v8::Isolate* isolate, v8::Handle<v8::Object> object, v8::Handle<v8::String> key, v8::Handle<v8::Value> value)
{
    return object->SetHiddenValue(key, value);
}
v8::Handle<v8::Object> toInnerGlobalObject(v8::Handle<v8::Context> context)
{
    return v8::Handle<v8::Object>::Cast(context->Global()->GetPrototype());
}
예제 #28
0
bool deleteHiddenValue(v8::Isolate* isolate, v8::Handle<v8::Object> object, v8::Handle<v8::String> key)
{
    return object->DeleteHiddenValue(key);
}
예제 #29
0
void init(v8::Handle<v8::Object> target) {
	// logger.start("/tmp/trustedtls/node.log", -1); // -1 = all levels bits
	// logger.start("logger.txt", LoggerLevel::All );

	// On Windows, we can't use Node's OpenSSL, so we link
	// to a standalone OpenSSL library. Therefore, we need
	// to initialize OpenSSL separately.

	// TODO: Do I need to free these?
	// I'm not sure where to call ERR_free_strings() and EVP_cleanup()

	// LOGGER_TRACE("OpenSSL init");

	OpenSSL::run();

	v8::Local<v8::Object> Pki = Nan::New<v8::Object>();

	target->Set(Nan::New("PKI").ToLocalChecked(), Pki);
	WCertificate::Init(Pki);
	WCertificateCollection::Init(Pki);
	WCRL::Init(Pki);
	WCrlCollection::Init(Pki);
	WOID::Init(Pki);
	WAlgorithm::Init(Pki);
	WAttribute::Init(Pki);
	WKey::Init(Pki);
	WCSR::Init(Pki);
	WCertificationRequestInfo::Init(Pki);
	WCertificationRequest::Init(Pki);
	WCipher::Init(Pki);
	WChain::Init(Pki);
	WPkcs12::Init(Pki);
	WRevocation::Init(Pki);


	v8::Local<v8::Object> Cms = Nan::New<v8::Object>();
	target->Set(Nan::New("CMS").ToLocalChecked(), Cms);
	WSignedData::Init(Cms);
	WSigner::Init(Cms);
	WSignerCollection::Init(Cms);
	WSignerAttributeCollection::Init(Cms);

	v8::Local<v8::Object> PkiStore = Nan::New<v8::Object>();
	target->Set(Nan::New("PKISTORE").ToLocalChecked(), PkiStore);
	WPkiStore::Init(PkiStore);
	WProvider_System::Init(PkiStore);
	#if defined(OPENSSL_SYS_WINDOWS)
		WProviderMicrosoft::Init(PkiStore);
	#endif
	#if defined(CPROCSP)
		WProviderCryptopro::Init(PkiStore);
	#endif
	WFilter::Init(PkiStore);
	WPkiItem::Init(PkiStore);
	WCashJson::Init(PkiStore);

	// target->Set(NanNew<v8::String>("utils"), NanNew<v8::Object>());
	// WLogger::Init(target->Get(NanNew<v8::String>("utils"))->ToObject());


	// logger.start("log-node.txt", LoggerLevel::Debug);
}
예제 #30
0
void PoiMergerJs::Init(v8::Handle<v8::Object> exports)
{
  exports->Set(v8::String::NewSymbol("poiMerge"), v8::FunctionTemplate::New(jsPoiMerge)->GetFunction());
}