当前位置: 首页>>代码示例>>C++>>正文


C++ Arguments::IsConstructCall方法代码示例

本文整理汇总了C++中Arguments::IsConstructCall方法的典型用法代码示例。如果您正苦于以下问题:C++ Arguments::IsConstructCall方法的具体用法?C++ Arguments::IsConstructCall怎么用?C++ Arguments::IsConstructCall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Arguments的用法示例。


在下文中一共展示了Arguments::IsConstructCall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ThrowException

Handle<Value> ImageView::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 << "image view external!\n";
        Local<External> ext = Local<External>::Cast(args[0]);
        void* ptr = ext->Value();
        ImageView* im =  static_cast<ImageView*>(ptr);
        im->Wrap(args.This());
        return args.This();
    } else {
            return ThrowException(String::New("Cannot create this object from Javascript"));
    }
    return Undefined();
}
开发者ID:booo,项目名称:node-mapnik,代码行数:19,代码来源:mapnik_image_view.cpp

示例2: SandboxWrapper

Handle<Value> NodeSandbox::node_new(const Arguments& args)
{
  HandleScope scope;

  if (args.IsConstructCall()) {
    SandboxWrapper* wrap = new SandboxWrapper();
    wrap->Wrap(args.This());
    wrap->nodeThis = wrap->handle_;
    node::MakeCallback (wrap->nodeThis, "_init", 0, nullptr);
    wrap->nodeThis->SetAccessor (String::NewSymbol ("debuggerOnCrash"), NodeSandbox::node_getDebugOnCrash, NodeSandbox::node_setDebugOnCrash);
    wrap->sbox->addIPC (std::unique_ptr<NodeIPC> (new NodeIPC (STDOUT_FILENO, wrap->handle_)));
    wrap->sbox->addIPC (std::unique_ptr<NodeIPC> (new NodeIPC (STDERR_FILENO, wrap->handle_)));

    return args.This();
  } else {
    Local<Value> argv[1] = { args[0] };
    return scope.Close(s_constructor->NewInstance(1, argv));
  }
}
开发者ID:codius,项目名称:codius-sandbox,代码行数:19,代码来源:sandbox-node-module.cpp

示例3: ThrowException

	/* ECMAScript constructor */
	Handle<Value> Viewport::New(const Arguments& args)
	{
		HandleScope scope;

		if (!args.IsConstructCall()) {
			return ThrowException(Exception::TypeError(
				String::New("Use the new operator to create instances of this object."))
			);
		}

		// Creates a new instance object of this type and wraps it.
		Viewport* obj = new Viewport();
		obj->Wrap(args.This());

		/* Initializing sub-objects */
		Local<Object> ScrollableObject = Scrollable::New(MX_SCROLLABLE(obj->_actor));
		args.Holder()->Set(String::NewSymbol("scroll"), ScrollableObject);

		return scope.Close(args.This());
	}
开发者ID:cfsghost,项目名称:jsdx-toolkit,代码行数:21,代码来源:viewport.cpp

示例4: ThrowException

Handle<Value> ItemObject::constructor(const Arguments &args)
{
	HandleScope handleScope;
	
	// Make sure the constructor is called with the new keyword
	
	if (!args.IsConstructCall())
	{
		Local<String> message = String::New("Cannot call constructor as a function");
		return ThrowException(Exception::SyntaxError(message));
	}
	
	// Instantiate a new ScriptTemplate
	
	ItemObject *itemObject = new ItemObject();
	Local<Object> itemInstance = itemObject->createInstance();
	itemInstance->SetInternalField(0, External::New(itemObject));
	
	return handleScope.Close(itemInstance);
}
开发者ID:bagobor,项目名称:BitRPG,代码行数:20,代码来源:ItemObject.cpp

示例5: ThrowException

Handle<Value> Palette::New(const Arguments& args) {
    HandleScope scope;

    if (!args.IsConstructCall()) {
        return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));
    }

    std::string palette;
    rgba_palette::palette_type type = rgba_palette::PALETTE_RGBA;
    if (args.Length() >= 1) {
        if (args[0]->IsString()) {
            String::AsciiValue obj(args[0]->ToString());
            palette = std::string(*obj, obj.length());
        }
        else if (node::Buffer::HasInstance(args[0])) {
            Local<Object> obj = args[0]->ToObject();
            palette = std::string(node::Buffer::Data(obj), node::Buffer::Length(obj));
        }
    }
    if (args.Length() >= 2) {
        if (args[1]->IsString()) {
            std::string obj = *String::Utf8Value(args[1]->ToString());
            if (obj == "rgb") type = rgba_palette::PALETTE_RGB;
            else if (obj == "act") type = rgba_palette::PALETTE_ACT;
        }
    }

    if (!palette.length()) {
        return ThrowException(Exception::TypeError(
            String::New("First parameter must be a palette string")));
    }

    Palette* p = new Palette(palette, type);
    if (!p->palette()->valid()) {
        delete p;
        return ThrowException(Exception::TypeError(String::New("Invalid palette length")));
    } else {
        p->Wrap(args.This());
        return args.This();
    }
}
开发者ID:gijs,项目名称:node-blend,代码行数:41,代码来源:palette.cpp

示例6: ThrowException

Handle<Value> Image::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();
        Image* im =  static_cast<Image*>(ptr);
        im->Wrap(args.This());
        return args.This();
    }

    try
    {
        if (args.Length() == 2)
        {
            if (!args[0]->IsNumber() || !args[1]->IsNumber())
                return ThrowException(Exception::Error(
                                          String::New("Image 'width' and 'height' must be a integers")));
            Image* im = new Image(args[0]->IntegerValue(),args[1]->IntegerValue());
            im->Wrap(args.This());
            return args.This();
        }
        else
        {
            return ThrowException(Exception::Error(
                                      String::New("please provide Image width and height")));
        }
    }
    catch (std::exception const& ex)
    {
        return ThrowException(Exception::Error(
                                  String::New(ex.what())));
    }
    return Undefined();
}
开发者ID:calvinmetcalf,项目名称:node-mapnik,代码行数:40,代码来源:mapnik_image.cpp

示例7: ThrowException

Handle<Value> MSOutputFormat::New(const Arguments &args) {
  HandleScope scope;
  MSOutputFormat *obj;
  
  if (!args.IsConstructCall()) {
    return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword"));
  }

  if (args[0]->IsExternal()) {
    Local<External> ext = Local<External>::Cast(args[0]);
    void* ptr = ext->Value();
    obj = static_cast<MSOutputFormat*>(ptr);
    obj->Wrap(args.This());
    return args.This();
  }
  
  REQ_STR_ARG(0, driver);
  REQ_STR_ARG(1, name);
  
  outputFormatObj *format = msCreateDefaultOutputFormat(NULL, *driver, *name);

  /* in the case of unsupported formats, msCreateDefaultOutputFormat
     should return NULL */
  if (!format) {
    msSetError(MS_MISCERR, "Unsupported format driver: %s",
               "outputFormatObj()", *driver);
    return args.This();
  }

  msInitializeRendererVTable(format);

  /* Else, continue */
  format->refcount++;
  format->inmapfile = MS_TRUE;
  
  obj = new MSOutputFormat(format);
  obj->Wrap(args.This());
  return args.This();
}
开发者ID:MarkHauenstein,项目名称:node-mapserver,代码行数:39,代码来源:ms_outputformat.cpp

示例8: ThrowException

Handle<Value> Tail::New(const Arguments& args) {
	HandleScope scope;
	
    assert(args.IsConstructCall());
    
    Tail* tail_instance = new Tail();
	tail_instance->Wrap(args.This());
    
    
	if (!args[0]->IsString())
		return ThrowException(Exception::TypeError(String::New("Argument 1 must be a String")));
	
    if (!args[1]->IsString())
		tail_instance->separator = "\n";
    else {
        String::Utf8Value v8separator(args[1]->ToString());
        tail_instance->separator = std::string(*v8separator, v8separator.length());
    }
    
	String::Utf8Value filename(args[0]);
    
    ifstream fp(*filename, ios::binary);
    fp.seekg(0, ios::end);
    tail_instance->last_position = fp.tellg();
    fp.close();
    
    tail_instance->_event_handle.data = reinterpret_cast<void*>(tail_instance);
    tail_instance->Ref();

    int r = uv_fs_event_init(uv_default_loop(), &tail_instance->_event_handle, *filename, OnEvent, 0);
    
    if (r == 0){
        tail_instance->ontail = false;
    } else
        node::SetErrno(uv_last_error(uv_default_loop()));
    
	return args.This();
}
开发者ID:dasher,项目名称:node-tail-native,代码行数:38,代码来源:tail.cpp

示例9: GNContext

// Create a context (new op)
Handle<Value> GNContext::New(const Arguments& args) {
    HandleScope scope;
    if (args.IsConstructCall()) {
        // new obj
        GNContext* ctx = new GNContext();
        getdns_return_t r = getdns_context_create(&ctx->context_, 1);
        if (r != GETDNS_RETURN_GOOD) {
            // Failed to create an underlying context
            delete ctx;
            ThrowException(Exception::Error(String::New("Unable to create GNContext.")));
        }
        // Apply options if needed
        if (args.Length() > 0) {
            // could throw an
            TryCatch try_catch;
            ctx->applyOptions(args[0]);
            if (try_catch.HasCaught()) {
                // Need to bail
                delete ctx;
                try_catch.ReThrow();
                return scope.Close(Undefined());
            }
        }
        // Attach the context to node
        bool attached = GNUtil::attachContextToNode(ctx->context_);
        if (!attached) {
            // Bail
            delete ctx;
            ThrowException(Exception::Error(String::New("Unable to attach to Node.")));
            return scope.Close(Undefined());
        }
        ctx->Wrap(args.This());
        return args.This();
    } else {
        ThrowException(Exception::Error(String::New("Must use new.")));
    }
    return scope.Close(Undefined());
}
开发者ID:gmadkat,项目名称:getdns-node,代码行数:39,代码来源:GNContext.cpp

示例10: ThrowException

Handle<Value> Projection::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.Length() > 0 || !args[0]->IsString()) {
      return ThrowException(Exception::TypeError(
        String::New("please provide a proj4 intialization string")));
  }
  try
  {
      Projection* p = new Projection(TOSTR(args[0]));
      p->Wrap(args.This());
      return args.This();
  }
  catch (const mapnik::proj_init_error & ex )
  {
    return ThrowException(Exception::Error(
      String::New(ex.what())));
  }
}
开发者ID:greco,项目名称:node-mapnik,代码行数:23,代码来源:mapnik_projection.cpp

示例11: NODE_THROW

Handle<Value> Point::New(const Arguments& args)
{
	HandleScope scope;
	Point *f;
	OGRPoint *geom;
	double x = 0, y = 0, z = 0;

	if (!args.IsConstructCall()) {
		return NODE_THROW("Cannot call constructor as function, you need to use 'new' keyword");
	}

	if (args[0]->IsExternal()) {
		Local<External> ext = Local<External>::Cast(args[0]);
		void* ptr = ext->Value();
		f = static_cast<Point *>(ptr);

	} else {
		NODE_ARG_DOUBLE_OPT(0, "x", x);
		NODE_ARG_DOUBLE_OPT(1, "y", y);
		NODE_ARG_DOUBLE_OPT(2, "z", z);

		if (args.Length() == 1) {
			return NODE_THROW("Point constructor must be given 0, 2, or 3 arguments");
		}

		if (args.Length() == 3) {
			geom = new OGRPoint(x, y, z);
		} else {
			geom = new OGRPoint(x, y);
		}

		f = new Point(geom);
	}

	f->Wrap(args.This());
	return args.This();
}
开发者ID:jarped,项目名称:node-gdal,代码行数:37,代码来源:gdal_point.cpp

示例12: ThrowException

Handle<Value> ZipFile::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.Length() != 1 || !args[0]->IsString())
        return ThrowException(Exception::TypeError(
                                  String::New("first argument must be a path to a zipfile")));

    std::string input_file = TOSTR(args[0]);
    struct zip *za;
    int err;
    char errstr[1024];
    if ((za = zip_open(input_file.c_str(), 0, &err)) == NULL) {
        zip_error_to_str(errstr, sizeof(errstr), err, errno);
        std::stringstream s;
        s << "cannot open file: " << input_file << " error: " << errstr << "\n";
        return ThrowException(Exception::Error(
                                  String::New(s.str().c_str())));
    }

    ZipFile* zf = new ZipFile(input_file);

    int num = zip_get_num_files(za);
    zf->names_.reserve(num);
    int i = 0;
    for (i = 0; i < num; i++) {
        struct zip_stat st;
        zip_stat_index(za, i, 0, &st);
        zf->names_.push_back(st.name);
    }

    zf->archive_ = za;
    zf->Wrap(args.This());
    return args.This();
}
开发者ID:anoopsinha,项目名称:maui-epub,代码行数:37,代码来源:node_zipfile.cpp

示例13: ThrowException

Handle<Value> Resolver::New(const Arguments& args) {
	HandleScope scope;

	if (!args.IsConstructCall()) {
		return ThrowException(Exception::TypeError(
				String::New("Use the new operator to create instances of this object."))
		);
	}

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

	Resolver* obj = new Resolver();
	String::Utf8Value name(args[0]->ToString());
	obj->name_ = std::string(*name);
	obj->resolver_ = new O3SResolver(obj->name_, false);

	if (obj->resolver_) {
		while (!obj->resolver_->getDico()) {
			std::cout<<"Waiting for dico..."<<std::endl;
			Poco::Thread::sleep(1000);
		}
		obj->Wrap(args.This());

		Local<Function> cb = Local<Function>::Cast(args[2]);
		const unsigned argc = 1;
		Local<Value> argv[argc] = { args.This() };
		cb->Call(Context::GetCurrent()->Global(), argc, argv);

		return args.This();
	}

	return Undefined();
}
开发者ID:vandrito,项目名称:node-o3s,代码行数:36,代码来源:resolver.cpp

示例14: ThrowException

  Handle<Value> FingerprintWrap::NewInstance(const Arguments& args) {
    HandleScope scope;

    if (!args.IsConstructCall())
      return ThrowException(Exception::TypeError(
        String::New("Use the new operator to create instances of this object.")));

    FingerprintWrap* fp = new FingerprintWrap(
      std::string(*String::AsciiValue(args[0]->ToString())).c_str(),
      args[1]->Int32Value(),
      args[2]->Int32Value(),
      args[3]->Int32Value(),
      args[4]->Int32Value());
    fp->Wrap(args.This());

    libtorrent::fingerprint* fp_ = FingerprintWrap::Unwrap(args.This());
    args.This()->Set(String::NewSymbol("name"),             String::New( fp_->name));
    args.This()->Set(String::NewSymbol("major_version"),    Integer::New(fp_->major_version));
    args.This()->Set(String::NewSymbol("minor_version"),    Integer::New(fp_->minor_version));
    args.This()->Set(String::NewSymbol("revision_version"), Integer::New(fp_->revision_version));
    args.This()->Set(String::NewSymbol("tag_version"),      Integer::New(fp_->tag_version));

    return scope.Close(args.This());
  };
开发者ID:Kimtn129,项目名称:node-libtorrent,代码行数:24,代码来源:fingerprint.cpp

示例15: ThrowException

Handle<Value> Nodehun::SpellDictionary::New(const Arguments& args) {
  HandleScope scope;
  int argl = args.Length();
  if (!args.IsConstructCall())
    return ThrowException(Exception::TypeError(String::New("Use the new operator to create instances of this object.")));
  if(argl < 1 || !args[0]->IsString())
    return ThrowException(Exception::TypeError(String::New("First argument must be a string.")));

  String::Utf8Value arg0(args[0]->ToString());
  Nodehun::SpellDictionary * obj;
  if(argl == 1 || argl > 1 && !args[1]->IsString()){    
    obj = new Nodehun::SpellDictionary(*arg0);
    if(!obj->pathsExist)
      return ThrowException(Exception::TypeError(String::New("No such dictionary exists.")));
  }
  else {
    String::Utf8Value arg1(args[1]->ToString());
    obj = new Nodehun::SpellDictionary(*arg0,*arg1);
    if(!obj->pathsExist)
      return ThrowException(Exception::TypeError(String::New("There was an error compiling either the affix or dictionary file you passed. Perhaps one or both of them is invalid.")));
  }
  obj->Wrap(args.This());  
  return args.This();
}
开发者ID:Alsan,项目名称:ONLYOFFICE-OnlineEditors,代码行数:24,代码来源:nodehun.cpp


注:本文中的Arguments::IsConstructCall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。