예제 #1
0
/* Generic constructor wrapper.
 * args[0]: row buffer
 * args[1]: array of blob & text column values
 * args.Data(): mapData holding the record and ColumnHandlers
 * args.This(): VO built from the mapping-specific InstanceTemplate
*/
Handle<Value> nroConstructor(const Arguments &args) {
  HandleScope scope;

  if(args.IsConstructCall()) {
    /* Unwrap record from mapData */
    Local<Object> mapData = args.Data()->ToObject();
    const Record * record = 
      unwrapPointer<const Record *>(mapData->Get(0)->ToObject());

    /* Unwrap Column Handlers from mapData */
    ColumnHandlerSet * handlers = 
      unwrapPointer<ColumnHandlerSet *>(mapData->Get(1)->ToObject());

    /* Build NdbRecordObject */
    NdbRecordObject * nro = new NdbRecordObject(record, handlers, args[0], args[1]);

    /* Wrap for JavaScript */
    wrapPointerInObject<NdbRecordObject *>(nro, nroEnvelope, args.This());
    freeFromGC(nro, args.This());
  }
  else {
    ThrowException(Exception::Error(String::New("must be a called as constructor")));
  }
  return args.This();
}
예제 #2
0
Handle<Value> AppjsSchemeHandler::NodeCallback(const Arguments& args) {
  HandleScope scope;

  AppjsSchemeHandler* me = static_cast<AppjsSchemeHandler *>(UnwrapObject(args.Data()));

  AutoLock lock_scope(me);

  me->status_      = args[0]->NumberValue();
  me->status_text_ = V8StringToChar(args[1]->ToString());
  me->mime_type_   = V8StringToChar(args[2]->ToString());
  me->data_        = node::Buffer::Data(args[4]->ToObject());
  me->data_length_ = node::Buffer::Length(args[4]->ToObject());

  Local<Object> headerSets = args[3]->ToObject();
  Local<Array> names = Local<Array>::Cast(headerSets->Get(String::NewSymbol("names")));
  Local<Array> headers = Local<Array>::Cast(headerSets->Get(String::NewSymbol("headers")));

  for(int i = 0; i < names->Length(); i++) {
    me->headers_.insert(
      std::pair<CefString,CefString>(
        V8StringToChar(names->Get(i)),
        V8StringToChar(headers->Get(i))
      )
    );
  }

  me->callback_->HeadersAvailable();

  return args.This();
}
예제 #3
0
파일: Interface.cpp 프로젝트: amolmk/anode
Handle<Value> Interface::PlatformOpInvoke(const Arguments& args) {
  HandleScope scope;
  jobject ob = (jobject)args.This()->GetPointerFromInternalField(0);
  int opData = args.Data()->Int32Value();
  int opIdx = opData & 0xffff;
  int clsid = opData >> 16;
  Env *env = Env::getEnv_nocheck();
  Interface *interface = env->getInterface(clsid);
  if(interface) {
    Operation *op = interface->operations->addr(opIdx);
    JNIEnv *jniEnv = interface->env->getVM()->getJNIEnv();
    jniEnv->PushLocalFrame(256);
    int result = OK;
    jobjectArray jArgs = 0;
    Local<Value> val;
    int expectedArgs = op->argCount;
    if(expectedArgs > 0) {
      jArgs = (jobjectArray)jniEnv->CallStaticObjectMethod(interface->jPlatformStub, interface->jPlatformGetArgs);
      jniEnv->MonitorEnter(jArgs);
      int suppliedArgs = args.Length();
      int argsToProcess = (suppliedArgs < expectedArgs) ? suppliedArgs : expectedArgs;
      jobject jItem;
      for(int i = 0; i < argsToProcess; i++) {
        result = interface->conv->ToJavaObject(jniEnv, args[i], op->argTypes[i], &jItem);
        if(result != OK) break;
        jniEnv->SetObjectArrayElement(jArgs, i, jItem);    
      }
      if(result == OK) {
        for(int i = argsToProcess; i < expectedArgs; i++) {
          result = interface->conv->ToJavaObject(jniEnv, Undefined(), op->argTypes[i], &jItem);
          if(result != OK) break;
          jniEnv->SetObjectArrayElement(jArgs, i, jItem);
        }
      }
    }
    if(result == OK) {
      jobject jVal = jniEnv->CallStaticObjectMethod(interface->jPlatformStub, interface->jPlatformInvoke, ob, opIdx, jArgs);
      if(env->getConv()->CheckForException(jniEnv)) {
        return Undefined();
      }
      if(result == OK) {
        result = interface->conv->ToV8Value(jniEnv, jVal, op->type, &val);
      }
    }
    if(expectedArgs > 0) {
      jniEnv->MonitorExit(jArgs);
    }
    jniEnv->PopLocalFrame(0);
    if(result == OK && !val.IsEmpty()) {
      return scope.Close(val);
    }
    interface->conv->ThrowV8ExceptionForErrno(result);
    LOGV("Interface::PlatformOpInvoke(): ret (error), result = %d\n", result);
  }
  return Undefined(); 
}
예제 #4
0
Handle<Value> Proxy::onPropertyChanged(const Arguments& args)
{
	if (args.Length() < 1) {
		return JSException::Error("Requires property name as first parameters.");
	}

	Local<String> name = args.Data()->ToString();
	Local<Value> value = args[0];
	onPropertyChangedForProxy(name, value, args.Holder());

	return Undefined();
}
예제 #5
0
    Handle< Value > V8Scope::loadCallback( const Arguments &args ) {
        HandleScope scope;
        Handle<External> field = Handle<External>::Cast(args.Data());
        void* ptr = field->Value();
        V8Scope* self = static_cast<V8Scope*>(ptr);

        Context::Scope context_scope(self->_context);
        for (int i = 0; i < args.Length(); ++i) {
            std::string filename(toSTLString(args[i]));
            if (!self->execFile(filename, false , true , false)) {
                return v8::ThrowException(v8::String::New((std::string("error loading file: ") + filename).c_str()));
            }
        }
        return v8::True();
    }
예제 #6
0
Handle<Value> AppjsSchemeHandler::NodeCallback(const Arguments& args) {

  HandleScope scope;

  AppjsSchemeHandler* me = static_cast<AppjsSchemeHandler *>(UnwrapObject(args.Data()));

  AutoLock lock_scope(me);

  me->status_      = args[0]->NumberValue();
  me->status_text_ = appjs::V8StringToChar(args[1]->ToString());
  me->mime_type_   = appjs::V8StringToChar(args[2]->ToString());
  me->data_        = node::Buffer::Data(args[3]->ToObject());
  me->data_length_ = node::Buffer::Length(args[3]->ToObject());

  me->callback_->HeadersAvailable();

  return args.This();
}
예제 #7
0
Handle<Value> BGJSView::js_view_on(const Arguments& args) {
	v8::Locker l;
	HandleScope scope;
	BGJSView *view = externalToClassPtr<BGJSView>(args.Data());
	if (args.Length() == 2 && args[0]->IsString() && args[1]->IsObject()) {
		Handle<Object> func = args[1]->ToObject();
		if (func->IsFunction()) {
			String::Utf8Value eventUtf8(args[0]->ToString());
			const char *event = *eventUtf8;
			if (strcmp(event, "event") == 0) {
				view->_cbEvent.push_back(Persistent<Object>::New(func));
			} else if (strcmp(event, "close") == 0) {
				view->_cbClose.push_back(Persistent<Object>::New(func));
			} else if (strcmp(event, "resize") == 0) {
				view->_cbResize.push_back(Persistent<Object>::New(func));
			} else if (strcmp(event, "redraw") == 0) {
				view->_cbRedraw.push_back(Persistent<Object>::New(func));
			}
		}
	}
	return v8::Undefined();
}
예제 #8
0
// Common function to handle getdns_address/service/hostname
Handle<Value> GNContext::HelperLookup(const Arguments& args) {
    // first argument is a string
    // last argument must be a callback
    // optional argument of extensions
    HandleScope scope;
    // name, type, and callback are required
    if (args.Length() < 2) {
        ThrowException(Exception::TypeError(String::New("At least 2 arguments are required.")));
    }
    // last arg must be a callback
    Local<Value> last = args[args.Length() - 1];
    if (!last->IsFunction()) {
        ThrowException(Exception::TypeError(String::New("Final argument must be a function.")));
    }
    Local<Function> localCb = Local<Function>::Cast(last);
    GNContext* ctx = node::ObjectWrap::Unwrap<GNContext>(args.This());
    if (!ctx || !ctx->context_) {
        Handle<Value> err = makeErrorObj("Context is invalid", GETDNS_RETURN_GENERIC_ERROR);
        Handle<Value> cbArgs[] = { err };
        localCb->Call(Context::GetCurrent()->Global(), 1, cbArgs);
        return scope.Close(Undefined());
    }
    // take first arg and make it a string
    String::Utf8Value name(args[0]->ToString());

    // 2nd arg could be extensions
    // optional third arg is an object
    getdns_dict* extension = NULL;
    if (args.Length() > 2 && args[1]->IsObject()) {
        extension = GNUtil::convertToDict(args[1]->ToObject());
    }

    // figure out what called us
    uint32_t funcType = args.Data()->Uint32Value();
    Persistent<Function> callback = Persistent<Function>::New(localCb);
    // create callback data
    CallbackData *data = new CallbackData();
    data->callback = callback;
    data->ctx = ctx;
    ctx->Ref();

    getdns_transaction_t transId;
    getdns_return_t r = GETDNS_RETURN_GOOD;
    if (funcType == GNAddress) {
        r = getdns_address(ctx->context_, *name, extension,
                           data, &transId, GNContext::Callback);
    } else if(funcType == GNService) {
        r = getdns_service(ctx->context_, *name, extension,
                           data, &transId, GNContext::Callback);
    } else {
        // hostname
        // convert to a dictionary..
        getdns_dict* ip = getdns_util_create_ip(*name);
        if (ip) {
            r = getdns_hostname(ctx->context_, ip, extension,
                                data, &transId, GNContext::Callback);
            getdns_dict_destroy(ip);
        } else {
            r = GETDNS_RETURN_GENERIC_ERROR;
        }
    }

    if (r != GETDNS_RETURN_GOOD) {
        // fail
        data->callback.Dispose();
        data->ctx->Unref();
        delete data;

        Handle<Value> err = makeErrorObj("Error issuing query", r);
        Handle<Value> cbArgs[] = { err };
        localCb->Call(Context::GetCurrent()->Global(), 1, cbArgs);
        return scope.Close(Undefined());
    }
    // done. return as buffer
    return scope.Close(GNUtil::convertToBuffer(&transId, 8));
}
예제 #9
0
Handle<Value> JSWrapper( const Arguments &args )
{
	JavaMethod* m = (JavaMethod*) External::Unwrap(args.Data());
	m->Invoke(args);
	return Undefined();
}
예제 #10
0
Handle<Value> Proxy::proxyConstructor(const Arguments& args)
{
	HandleScope scope;
	JNIEnv *env = JNIScope::getEnv();
	Local<Object> jsProxy = args.Holder();

	Handle<Object> properties = Object::New();
	jsProxy->Set(propertiesSymbol, properties, PropertyAttribute(DontEnum));

	Handle<Object> prototype = jsProxy->GetPrototype()->ToObject();

	Handle<Function> constructor = Handle<Function>::Cast(prototype->Get(constructorSymbol));
	jclass javaClass = (jclass) External::Unwrap(constructor->Get(javaClassSymbol));

	// If ProxyFactory::createV8Proxy invoked us, unwrap
	// the pre-created Java proxy it sent.
	jobject javaProxy = ProxyFactory::unwrapJavaProxy(args);
	bool deleteRef = false;
	if (!javaProxy) {
		javaProxy = ProxyFactory::createJavaProxy(javaClass, jsProxy, args);
		deleteRef = true;
	}

	JNIUtil::logClassName("Create proxy: %s", javaClass);

	Proxy *proxy = new Proxy(javaProxy);
	proxy->Wrap(jsProxy);

	int length = args.Length();

	if (length > 0 && args[0]->IsObject()) {
		/*
		Handle<Value> argsStr = V8Util::jsonStringify(args[0]);
		String::Utf8Value str(argsStr);
		LOGV(TAG, "    with args: %s", *str);
		*/

		bool extend = true;
		Handle<Object> createProperties = args[0]->ToObject();
		Local<String> constructorName = createProperties->GetConstructorName();
		if (strcmp(*String::Utf8Value(constructorName), "Arguments") == 0) {
			extend = false;
			int32_t argsLength = createProperties->Get(String::New("length"))->Int32Value();
			if (argsLength > 1) {
				Handle<Value> properties = createProperties->Get(1);
				if (properties->IsObject()) {
					extend = true;
					createProperties = properties->ToObject();
				}
			}
		}

		if (extend) {
			Handle<Array> names = createProperties->GetOwnPropertyNames();
			int length = names->Length();

			for (int i = 0; i < length; ++i) {
				Handle<Value> name = names->Get(i);
				Handle<Value> value = createProperties->Get(name);
				bool isProperty = true;
				if (name->IsString()) {
					Handle<String> nameString = name->ToString();
					if (!jsProxy->HasRealNamedCallbackProperty(nameString)
						&& !jsProxy->HasRealNamedProperty(nameString)) {
						jsProxy->Set(name, value);
						isProperty = false;
					}
				}
				if (isProperty) {
					properties->Set(name, value);
				}
			}
		}
	}


	if (!args.Data().IsEmpty() && args.Data()->IsFunction()) {
		Handle<Function> proxyFn = Handle<Function>::Cast(args.Data());
		Handle<Value> *fnArgs = new Handle<Value>[length];
		for (int i = 0; i < length; ++i) {
			fnArgs[i] = args[i];
		}
		proxyFn->Call(jsProxy, length, fnArgs);
	}

	if (deleteRef) {
		JNIEnv *env = JNIScope::getEnv();
		if (env) {
			env->DeleteLocalRef(javaProxy);
		}
	}

	return jsProxy;
}