Esempio n. 1
0
Handle<Value> jsWindow::PlaceHolder(const Arguments& args)
{
    Local<Object> self = args.This();
    Local<External> wrap = Local<External>::Cast(self->GetInternalField(0));
    void* ptr = wrap->Value();
    jsWindow* el = static_cast<jsWindow*>(ptr);

    string ret;
    ret = value_to_string(args.Callee()->ToString());
    ret += " [Window; uuid=";
    ret += el->win_uuid;
    ret += "; name=";
    ret += value_to_string(el->props["name"]->ToString());
    ret += "]";
    LOG4CXX_DEBUG(iLogger::GetLogger(), _T("jsWindow::PlaceHolder - ") << ret);
    return String::New(ret.c_str());
}
Esempio n. 2
0
 Handle< Value > V8Scope::nativeCallback( const Arguments &args ) {
     Local< External > f = External::Cast( *args.Callee()->Get( v8::String::New( "_native_function" ) ) );
     NativeFunction function = ( NativeFunction )( f->Value() );
     BSONObjBuilder b;
     for( int i = 0; i < args.Length(); ++i ) {
         stringstream ss;
         ss << i;
         v8ToMongoElement( b, v8::String::New( "foo" ), ss.str(), args[ i ] );
     }
     BSONObj ret;
     try {
         ret = function( b.done() );
     } catch( const std::exception &e ) {
         return v8::ThrowException(v8::String::New(e.what()));
     } catch( ... ) {
         return v8::ThrowException(v8::String::New("unknown exception"));            
     }
     return mongoToV8Element( ret.firstElement() );
 }
Esempio n. 3
0
Handle<Value> jsBrowser::WinInterceptor( const Arguments& args )
{
    Handle<Value> retval;
    Local<Context> ctx = v8::Context::GetCurrent();
    Local<Object> exec = Local<Object>::Cast(ctx->Global()->Get(String::New("v8_context")));
    Local<External> wrap = Local<External>::Cast(exec->GetInternalField(0));
    void* ptr = wrap->Value();
    jsBrowser* el = static_cast<jsBrowser*>(ptr);

    string fname = value_to_string(args.Callee()->GetName()->ToString());

    Local<Object> _obj = Local<Object>::New(v8_wrapper::wrap_object<jsWindow>(el->window));
    Local<Function> _func = Local<Function>::Cast(_obj->Get(String::New(fname.c_str())));
    Handle<Value> *fargs = new Handle<Value>[args.Length()];
    for (int i = 0; i < args.Length(); ++i) {
        fargs[i] = args[i];
    }
    retval = _func->Call(_obj, args.Length(), fargs );

    return retval;
}
Esempio n. 4
0
jobject ProxyFactory::createJavaProxy(jclass javaClass, Local<Object> v8Proxy, const Arguments& args)
{
	ProxyInfo* info;
	GET_PROXY_INFO(javaClass, info);

	if (!info) {
		JNIUtil::logClassName("ProxyFactory: failed to find class for %s", javaClass, true);
		LOGE(TAG, "No proxy info found for class.");
		return NULL;
	}

	JNIEnv* env = JNIScope::getEnv();
	if (!env) {
		LOG_JNIENV_ERROR("while creating Java proxy.");
		return NULL;
	}

	// Create a persistent handle to the V8 proxy
	// and cast it to a pointer. The Java proxy needs
	// a reference to the V8 proxy for later use.
	Proxy* proxy = NativeObject::Unwrap<Proxy>(v8Proxy);
	jlong pv8Proxy = (jlong) *(proxy->handle_);

	// We also pass the creation URL of the proxy so we can track relative URLs
	Handle<Value> sourceUrl = args.Callee()->GetScriptOrigin().ResourceName();
	String::Utf8Value sourceUrlValue(sourceUrl);

	const char *url = "app://app.js";
	jstring javaSourceUrl = NULL;
	if (sourceUrlValue.length() > 0) {
		url = *sourceUrlValue;
		javaSourceUrl = env->NewStringUTF(url);
	}

	// Determine if this constructor call was made within
	// the createXYZ() wrapper function. This can be tested by checking
	// if an Arguments object was passed as the sole argument.
	bool calledFromCreate = false;
	if (args.Length() == 1 && args[0]->IsObject()) {
		if (V8Util::constructorNameMatches(args[0]->ToObject(), "Arguments")) {
			calledFromCreate = true;
		}
	}

	// Convert the V8 arguments into Java types so they can be
	// passed to the Java creator method. Which converter we use
	// depends how this constructor was called.
	jobjectArray javaArgs;
	if (calledFromCreate) {
		Local<Object> arguments = args[0]->ToObject();
		int length = arguments->Get(Proxy::lengthSymbol)->Int32Value();
		int start = 0;

		// Get the scope variables if provided and extract the source URL.
		// We need to send that to the Java side when creating the proxy.
		if (length > 0) {
			Local<Object> scopeVars = arguments->Get(0)->ToObject();
			if (V8Util::constructorNameMatches(scopeVars, "ScopeVars")) {
				Local<Value> sourceUrl = scopeVars->Get(Proxy::sourceUrlSymbol);
				javaSourceUrl = TypeConverter::jsValueToJavaString(sourceUrl);
				start = 1;
			}
		}

		javaArgs = TypeConverter::jsObjectIndexPropsToJavaArray(arguments, start, length);
	} else {
		javaArgs = TypeConverter::jsArgumentsToJavaArray(args);
	}

	jobject javaV8Object = env->NewObject(JNIUtil::v8ObjectClass,
		JNIUtil::v8ObjectInitMethod, pv8Proxy);

	// Create the java proxy using the creator static method provided.
	// Send along a pointer to the v8 proxy so the two are linked.
	jobject javaProxy = env->CallStaticObjectMethod(JNIUtil::krollProxyClass,
		info->javaProxyCreator, javaClass, javaV8Object, javaArgs, javaSourceUrl);

	if (javaSourceUrl) {
		LOGV(TAG, "delete source url!");
		env->DeleteLocalRef(javaSourceUrl);
	}

	env->DeleteLocalRef(javaV8Object);
	env->DeleteLocalRef(javaArgs);

	return javaProxy;
}