예제 #1
0
Handle<Value>
DynamicJpegStack::New(const Arguments &args)
{
    HandleScope scope;

    if (args.Length() > 1)
        return VException("One argument max - buffer type.");

    buffer_type buf_type = BUF_RGB;
    if (args.Length() == 1) {
        if (!args[0]->IsString())
            return VException("First argument must be a string. Either 'rgb', 'bgr', 'rgba' or 'bgra'.");

        String::AsciiValue bt(args[0]->ToString());
        if (!(str_eq(*bt, "rgb") || str_eq(*bt, "bgr") ||
                str_eq(*bt, "rgba") || str_eq(*bt, "bgra")))
        {
            return VException("Buffer type must be 'rgb', 'bgr', 'rgba' or 'bgra'.");
        }

        if (str_eq(*bt, "rgb"))
            buf_type = BUF_RGB;
        else if (str_eq(*bt, "bgr"))
            buf_type = BUF_BGR;
        else if (str_eq(*bt, "rgba"))
            buf_type = BUF_RGBA;
        else if (str_eq(*bt, "bgra"))
            buf_type = BUF_BGRA;
        else
            return VException("Buffer type wasn't 'rgb', 'bgr', 'rgba' or 'bgra'.");
    }

    DynamicJpegStack *jpeg = new DynamicJpegStack(buf_type);
    jpeg->Wrap(args.This());
    return args.This();
}
예제 #2
0
/**
 * Executes a command.
 */
Handle<Value> Exec(const Arguments& args) {
    HandleScope scope;

    if (args.Length() < 1) {
        return ThrowException(
            Exception::TypeError(String::New("First argument must be a string"))
        );
    }

    Local<String> str = args[0]->ToString();
    std::string cmd = FlattenString(str);
    int result = exec(cmd.c_str());

    return scope.Close(Integer::New(result));
}
예제 #3
0
Handle<Value> DecoderNotifier::Done(const Arguments& args) {
  HandleScope scope;

  DecoderNotifier* obj = ObjectWrap::Unwrap<DecoderNotifier>(args.This());
  
 if(args.Length() == 0){
    // Process next frame
    uv_queue_work(uv_default_loop(),
                  &(obj->pBaton->request),
                  AsyncWork,
                  (uv_after_work_cb)AsyncAfter);
  }
  
  return Undefined();
}
예제 #4
0
Handle< ::v8::Value> GlobalVariable::New(const Arguments& args)
{
    HandleScope scope;
    if (args.Length()) {
        REQ_LLVM_MODULE_ARG(0, module);
        REQ_LLVM_TYPE_ARG(1, type);
        REQ_UTF8_ARG(2, name);
        REQ_LLVM_CONST_ARG(3, init);

        GlobalVariable* val = new GlobalVariable(new ::llvm::GlobalVariable(*module, type, false, llvm::GlobalValue::InternalLinkage, init, *name));

        val->Wrap(args.This());
    }
    return args.This();
}
예제 #5
0
파일: bind.cpp 프로젝트: Qard/jsgame
Handle<Value> ALUTLoadMemoryHelloWorldCallback(const Arguments& args) {
	//if less that nbr of formal parameters then do nothing
	if (args.Length() < 3)
		return v8::Undefined();
	
	//get arguments
	Handle<Array> arg0 = Array::Cast(args[0]);
	Handle<Array> arg1 = Array::Cast(args[1]);
	Handle<Array> arg2 = Array::Cast(args[2]);

	//make call
	alutLoadMemoryHelloWorld((ALenum*)arg0, (ALsizei*)arg1, (ALfloat*)arg2);
	
	return v8::Undefined();
}
예제 #6
0
파일: bind.cpp 프로젝트: Qard/jsgame
Handle<Value> ALUTCreateBufferFromFileImageCallback(const Arguments& args) {
	//if less that nbr of formal parameters then do nothing
	if (args.Length() < 2)
		return v8::Undefined();
	
	//get arguments
	String::Utf8Value value0(args[0]);
	char* key0 = *value0;
	void* arg0 = font_[key0];

	//make call
	alutCreateBufferFromFileImage((const ALvoid*)arg0, (ALsizei)arg1);
	
	return v8::Undefined();
}
예제 #7
0
파일: bind.cpp 프로젝트: Qard/jsgame
Handle<Value> ALUTInitWithoutContextCallback(const Arguments& args) {
	//if less that nbr of formal parameters then do nothing
	if (args.Length() < 2)
		return v8::Undefined();
	
	//get arguments
	Handle<Array> arg0 = Array::Cast(args[0]);
	String::Utf8Value value1(args[1]);
	char* arg1 = *value1;

	//make call
	alutInitWithoutContext((int*)arg0, (char**)arg1);
	
	return v8::Undefined();
}
예제 #8
0
Handle<Value> Expression::New(const Arguments& args)
{
    HandleScope scope;
    if (!args.IsConstructCall())
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));

    if (args[0]->IsExternal())
    {
        //std::clog << "external!\n";
        Local<External> ext = Local<External>::Cast(args[0]);
        void* ptr = ext->Value();
        Expression* e = static_cast<Expression*>(ptr);
        e->Wrap(args.This());
        return args.This();
    }

    mapnik::expression_ptr e_ptr;
    try
    {
        if (args.Length() == 1 && args[0]->IsString()){
            e_ptr = mapnik::parse_expression(TOSTR(args[0]),"utf8");

        } else {
            return ThrowException(Exception::Error(
                                      String::New("invalid arguments: accepts a single argument of string type")));
        }
    }
    catch (std::exception const& ex)
    {
        return ThrowException(Exception::Error(
                                  String::New(ex.what())));
    }

    if (e_ptr)
    {
        Expression* e = new Expression();
        e->Wrap(args.This());
        e->this_ = e_ptr;
        return args.This();
    }
    else
    {
        return ThrowException(Exception::Error(
                                  String::New("unknown exception happened, please file bug")));
    }

    return Undefined();
}
예제 #9
0
// メソッドの呼び出し
Handle<Value>
TJSObject::caller(const Arguments& args)
{
	tTJSVariant self;
	if (getVariant(self, args.This())) {
		Handle<Value> ret;
		
		// 引数変換
		tjs_int argc = args.Length();
		tTJSVariant **argv = new tTJSVariant*[argc];
		for (tjs_int i=0;i<argc;i++) {
			argv[i] = new tTJSVariant();
			*argv[i] = toVariant(args[i]);
		}

		if (self.AsObjectClosureNoAddRef().IsInstanceOf(0, NULL, NULL, L"Class", NULL) == TJS_S_TRUE) {
			// クラスオブジェクトならコンストラクタ呼び出し
			iTJSDispatch2 *instance = NULL;
			tjs_error error;
			if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().CreateNew(0, NULL, NULL, &instance, argc, argv, NULL))) {
				ret = toJSValue(tTJSVariant(instance, instance));
				instance->Release();
			} else {
				ret = ERROR_KRKR(error);
			}
		} else {
			// メソッド呼び出し
			tTJSVariant result;
			tjs_error error;
			if (TJS_SUCCEEDED(error = self.AsObjectClosureNoAddRef().FuncCall(0, NULL, NULL, &result, argc, argv, NULL))) {
				ret = toJSValue(result);
			} else {
				ret = ERROR_KRKR(error);
			}
		}

		// 引数解放
		if (argv) {
			for (int i=0;i<argc;i++) {
				delete argv[i];
			}
			delete[] argv;
		}
		
		return ret;
	}
	return ERROR_BADINSTANCE();
}
Handle<Value> TiAppPropertiesObject::_removeProperty(void* /*userContext*/, TiObject* /*caller*/, const Arguments& args)
{
    if (args.Length() < 1)
    {
        return ThrowException(String::New(Ti::Msg::Missing_argument));
    }
    if (!args[0]->IsString() && !args[0]->IsStringObject())
    {
        return ThrowException(String::New((string(Ti::Msg::Invalid_argument_expected_) + "String").c_str()));
    }

    QString key = QString::fromUtf8(*String::Utf8Value(args[0]));
    settings.remove(key);

    return Undefined();
}
예제 #11
0
Handle<Value> Scene_GetMainComponent(const Arguments& args)
{
    HandleScope handle_scope;

    Scene* ptr = GetPtr(args.This());
    assert(ptr);

    Component* pComponent = 0;

    if ((args.Length() == 1) && args[0]->IsUint32())
        pComponent = ptr->getMainComponent((tComponentType) args[0]->ToUint32()->Value());
    else
        return ThrowException(String::New("Invalid parameters, valid syntax:\ngetMainComponent(type)"));

    return handle_scope.Close(toJavaScript(pComponent));
}
예제 #12
0
Handle<Value> Grid::view(const Arguments& args)
{
    HandleScope scope;

    if ( (args.Length() != 4) || (!args[0]->IsNumber() && !args[1]->IsNumber() && !args[2]->IsNumber() && !args[3]->IsNumber() ))
        return ThrowException(Exception::TypeError(
                                  String::New("requires 4 integer arguments: x, y, width, height")));

    unsigned x = args[0]->IntegerValue();
    unsigned y = args[1]->IntegerValue();
    unsigned w = args[2]->IntegerValue();
    unsigned h = args[3]->IntegerValue();

    Grid* g = ObjectWrap::Unwrap<Grid>(args.This());
    return scope.Close(GridView::New(g,x,y,w,h));
}
예제 #13
0
v8::Handle<v8::Value> CompoundShape_GetChildShape(const Arguments& args)
{
    HandleScope handle_scope;

    if ((args.Length() == 1) && args[0]->IsUint32())
    {
        CompoundShape* ptr = GetPtr(args.This());
        assert(ptr);

        unsigned int index = args[0]->ToUint32()->Value();
        if (index < ptr->getNbChildShapes())
            return handle_scope.Close(Uint32::New((unsigned int) ptr->getChildShape(index)));
    }

    return ThrowException(String::New("Invalid parameters, valid syntax:\ngetChildShape(childIndex)"));
}
예제 #14
0
Handle<Value> ComponentsManager_Create(const Arguments& args)
{
    HandleScope handle_scope;

    ComponentsManager* ptr = GetPtr(args.This());
    assert(ptr);

    if ((args.Length() == 3) && args[0]->IsString() && args[1]->IsString() && args[2]->IsObject())
    {
        return handle_scope.Close(toJavaScript(ptr->create(*String::AsciiValue(args[0]->ToString()),
                                                           *String::AsciiValue(args[1]->ToString()),
                                                           fromJSComponentsList(args[2]))));
    }

    return ThrowException(String::New("Invalid parameters, valid syntax:\ncreate(type, name, components_list)"));
}
예제 #15
0
파일: nodehun.cpp 프로젝트: nojose/nodehun
Handle<Value> Nodehun::SpellDictionary::New(const Arguments& args) {
  HandleScope scope;
  int argl = args.Length();
  if (!args.IsConstructCall())
    return ThrowException(Exception::Error(String::New("Use the new operator to create an instance of this object.")));
  if(argl < 2)
    return ThrowException(Exception::Error(String::New("Constructor requires two arguments.")));
  if(!Buffer::HasInstance(args[0]))
    return ThrowException(Exception::TypeError(String::New("First argument must be a buffer")));
  if(!Buffer::HasInstance(args[1]))
    return ThrowException(Exception::TypeError(String::New("Second argument must be a buffer")));

  Nodehun::SpellDictionary *obj = new Nodehun::SpellDictionary(Buffer::Data(args[0].As<Object>()), Buffer::Data(args[1].As<Object>()));
  obj->Wrap(args.This());  
  return args.This();
}
예제 #16
0
Handle<Value> PDFDateDriver::NewInstance(const Arguments& args)
{
    HandleScope scope;
    
    if(args.Length() != 1 || !args[0]->IsDate())
    {
		ThrowException(Exception::TypeError(String::New("Wrong arguments. Provide 1 argument which is a date")));
        return scope.Close(Undefined());
    }
    
    const unsigned argc = 1;
    Handle<Value> argv[argc] = {args[0]};
    Local<Object> instance = constructor->NewInstance(argc, argv);
    
    return scope.Close(instance);
}
예제 #17
0
Handle<Value> NovaConfigBinding::AddIface(const Arguments& args)
{
  HandleScope scope;
  NovaConfigBinding* obj = ObjectWrap::Unwrap<NovaConfigBinding>(args.This());
  
  if(args.Length() < 1)
  {
      return ThrowException(Exception::TypeError(String::New("Must be invoked with one parameter")));
  }
  
  std::string pass = cvv8::CastFromJS<std::string>(args[0]);
  
  obj->m_conf->AddInterface(pass);
  
  return args.This();
}
예제 #18
0
Handle<Value> HoneydConfigBinding::RenamePortset(const Arguments& args)
{
	HandleScope scope;
	HoneydConfigBinding* obj = ObjectWrap::Unwrap<HoneydConfigBinding>(args.This());

	if(args.Length() != 3)
	{
		return ThrowException(Exception::TypeError(String::New("Must be invoked with 3 parameters")));
	}

	std::string oldName = cvv8::CastFromJS<string>(args[0]);
	std::string newName = cvv8::CastFromJS<string>(args[1]);
	std::string profile = cvv8::CastFromJS<string>(args[2]);

	return scope.Close(Boolean::New(obj->m_conf->RenamePortset(profile, oldName, newName)));
}
예제 #19
0
Handle<Value> Signal_Fire(const Arguments& args)
{
    HandleScope handle_scope;

    Signal* self = GetPtr(args.This());
    assert(self);

    Variant* pValue = 0;

    if (args.Length() == 1)
        pValue = fromJSVariant(args[0]);

    self->fire(pValue);

    return Handle<Value>();
}
예제 #20
0
// --------------------------------------------------------
Handle<Value> NodeOpenALStream::Buffer(const Arguments& args) {
	HandleScope scope;
	NodeOpenALStream* obj = ObjectWrap::Unwrap<NodeOpenALStream>(args.This());

	if (args.Length() < 1) {
		ThrowException(Exception::TypeError(String::New("Wrong number of arguments")));
		return scope.Close( Undefined() );
	}

	Local<Value> buffer = args[0];
	size_t size = node::Buffer::Length( buffer->ToObject() );
	char* bufferdata = node::Buffer::Data( buffer->ToObject() );

	obj->buffer(size, bufferdata);
	return scope.Close(v8::Undefined());
}
예제 #21
0
파일: glescustom.cpp 프로젝트: Qard/jsgame
Handle<Value> GLESglGetProgramInfoLogCallback(const Arguments& args) {
	if (args.Length() != 1)
		return v8::Undefined();
	
	//get arguments
	unsigned program = args[0]->Uint32Value();

	//query string length
	int len = 0;
	glGetProgramiv((GLuint)program, GL_INFO_LOG_LENGTH, &len);

	char* log = new char[len];
	glGetProgramInfoLog((GLuint)program, (GLsizei)len, NULL, log);

	return String::New(log);
}
예제 #22
0
파일: glescustom.cpp 프로젝트: Qard/jsgame
Handle<Value> GLESglGetProgramivCallback(const Arguments& args) {
	//if less that nbr of formal parameters then do nothing
	if (args.Length() != 2)
		return v8::Undefined();
	
	//get arguments
	unsigned program = args[0]->Uint32Value();
	unsigned pname = args[1]->Uint32Value();
	int ans;

	//TODO(nico): I haven't seen any case where this function might return
	//an array.
	glGetProgramiv((GLuint)program, (GLenum)pname, (GLint*) &ans);

	return Integer::New(ans);
}
예제 #23
0
파일: glescustom.cpp 프로젝트: Qard/jsgame
Handle<Value> GLESglGetShaderSourceCallback(const Arguments& args) {
	if (args.Length() != 1)
		return v8::Undefined();
	
	//get arguments
	unsigned shader = args[0]->Uint32Value();

	//query string length
	int len = 0;
	glGetShaderiv((GLuint)shader, GL_SHADER_SOURCE_LENGTH, &len);

	char* log = new char[len];
	glGetShaderSource((GLuint)shader, (GLsizei)len, NULL, log);

	return String::New(log);
}
예제 #24
0
파일: engine_v8.cpp 프로젝트: IlyaM/mongo
    Handle< Value > V8Scope::loadCallback( const Arguments &args ) {
        Locker l;
        HandleScope handle_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();
    }
예제 #25
0
Handle<Value> alert(const Arguments& args)
{
    bool first = true;
    string res = "";
    for (int i = 0; i < args.Length(); i++) {
        HandleScope handle_scope;
        if (first) {
            first = false;
        } else {
            res += " ";
        }
        res += value_to_string(args[i]);
    }
    LOG4CXX_INFO(webEngine::iLogger::GetLogger(), _T("js::alert: ") << res);
    return Undefined();
}
예제 #26
0
Handle<Value> NovaConfigBinding::UseAnyLoopback(const Arguments& args) 
{
  HandleScope scope;
  NovaConfigBinding* obj = ObjectWrap::Unwrap<NovaConfigBinding>(args.This());

    if( args.Length() < 1 )
    {
        return ThrowException(Exception::TypeError(String::New("Must be invoked with one parameter")));
    }

    bool def = cvv8::CastFromJS<bool>( args[0] );

  obj->m_conf->SetUseAnyLoopback(def);

  return args.This();
}
예제 #27
0
Handle<Value> NovaConfigBinding::WriteSetting(const Arguments& args) 
{
	HandleScope scope;
	NovaConfigBinding* obj = ObjectWrap::Unwrap<NovaConfigBinding>(args.This());

	if( args.Length() != 2 )
	{
		return ThrowException(Exception::TypeError(String::New("Must be invoked with two parameters")));
	}

	string key = cvv8::CastFromJS<string>( args[0] );
	string value = cvv8::CastFromJS<string>( args[1] );


	return scope.Close(Boolean::New(obj->m_conf->WriteSetting(key, value)));
}
예제 #28
0
Handle<Value> ImageHashAsync(const Arguments& args) {
    if (args.Length() < 2 || !args[1]->IsFunction()) {
        // no callback defined
        return ThrowException(Exception::Error(String::New("Callback is required and must be an Function.")));
    }

    String::Utf8Value str(args[0]);
    Handle<Function> cb = Handle<Function>::Cast(args[1]);
    
    PhashRequest* request = new PhashRequest;
    request->callback = Persistent<Function>::New(cb);
    request->file = string(*str);
    request->request.data = request;
    uv_queue_work(uv_default_loop(), &request->request, HashWorker, HashAfter);
    return Undefined();
}
예제 #29
0
Handle<Value> NovaConfigBinding::SetDoppelInterface(const Arguments& args)
{
	HandleScope scope;
	
	if(args.Length() != 1)
	{
		return ThrowException(Exception::TypeError(String::New("Must be invoked with one parameter")));
	}
	
	NovaConfigBinding* obj = ObjectWrap::Unwrap<NovaConfigBinding>(args.This());
	std::string difToSet = cvv8::CastFromJS<std::string>(args[0]);
	
	obj->m_conf->SetDoppelInterface(difToSet);
	
	return args.This();
}
Handle<Value> TiTitaniumObject::_createBuffer(void* userContext, TiObject*, const Arguments& args)
{
    HandleScope handleScope;
    TiTitaniumObject* obj = (TiTitaniumObject*) userContext;
    Handle<ObjectTemplate> global = getObjectTemplateFromJsObject(args.Holder());
    Handle<Object> result = global->NewInstance();
    TiBufferObject* newBuffer = TiBufferObject::createBuffer(obj->objectFactory_);
    newBuffer->setValue(result);
    if ((args.Length() > 0) && (args[0]->IsObject()))
    {
        Local<Object> settingsObj = Local<Object>::Cast(args[0]);
        newBuffer->setParametersFromObject(newBuffer, settingsObj);
    }
    setTiObjectToJsObject(result, newBuffer);
    return handleScope.Close(result);
}