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


C++ JS_NewArrayObject函数代码示例

本文整理汇总了C++中JS_NewArrayObject函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_NewArrayObject函数的具体用法?C++ JS_NewArrayObject怎么用?C++ JS_NewArrayObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: ReflectHistogramSnapshot

JSBool
ReflectHistogramSnapshot(JSContext *cx, JSObject *obj, Histogram *h)
{
  Histogram::SampleSet ss;
  h->SnapshotSample(&ss);
  JSObject *counts_array;
  JSObject *rarray;
  jsval static_histogram = h->flags() && Histogram::kUmaTargetedHistogramFlag ? JSVAL_TRUE : JSVAL_FALSE;
  const size_t count = h->bucket_count();
  if (!(JS_DefineProperty(cx, obj, "min", INT_TO_JSVAL(h->declared_min()), NULL, NULL, JSPROP_ENUMERATE)
        && JS_DefineProperty(cx, obj, "max", INT_TO_JSVAL(h->declared_max()), NULL, NULL, JSPROP_ENUMERATE)
        && JS_DefineProperty(cx, obj, "histogram_type", INT_TO_JSVAL(h->histogram_type()), NULL, NULL, JSPROP_ENUMERATE)
        && JS_DefineProperty(cx, obj, "sum", DOUBLE_TO_JSVAL(ss.sum()), NULL, NULL, JSPROP_ENUMERATE)
        && (rarray = JS_NewArrayObject(cx, count, NULL))
        && JS_DefineProperty(cx, obj, "ranges", OBJECT_TO_JSVAL(rarray), NULL, NULL, JSPROP_ENUMERATE)
        && FillRanges(cx, rarray, h)
        && (counts_array = JS_NewArrayObject(cx, count, NULL))
        && JS_DefineProperty(cx, obj, "counts", OBJECT_TO_JSVAL(counts_array), NULL, NULL, JSPROP_ENUMERATE)
        && JS_DefineProperty(cx, obj, "static", static_histogram, NULL, NULL, JSPROP_ENUMERATE)
        )) {
    return JS_FALSE;
  }
  for (size_t i = 0; i < count; i++) {
    if (!JS_DefineElement(cx, counts_array, i, INT_TO_JSVAL(ss.counts(i)), NULL, NULL, JSPROP_ENUMERATE)) {
      return JS_FALSE;
    }
  }
  return JS_TRUE;
}
开发者ID:vingtetun,项目名称:mozilla-central,代码行数:29,代码来源:Telemetry.cpp

示例2: make_array

    JSObject* make_array( JSContext* ctx, int size ) {
        // https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_NewArrayObject
#if MOZJS_MAJOR_VERSION >= 31
        return JS_NewArrayObject(ctx, size);
#else
        return JS_NewArrayObject(ctx, size, NULL);
#endif
    }
开发者ID:sdkbox,项目名称:sdkbox-sample-appnext,代码行数:8,代码来源:SDKBoxJSHelper.cpp

示例3: create_search_paths

static void
create_search_paths (GjsRequire *self)
{
  JSAutoCompartment ac(self->priv->context, JS_GetGlobalObject (self->priv->context));
  /* create exported (accessible from JS) 'paths' array */
  self->priv->exported_paths = JS_NewArrayObject (self->priv->context, 0, NULL);
  g_assert (self->priv->exported_paths != NULL);

  /* create private paths array */
  self->priv->private_paths = JS_NewArrayObject (self->priv->context, 0, NULL);
  g_assert (self->priv->private_paths != NULL);
}
开发者ID:groleo,项目名称:gjs-commonjs,代码行数:12,代码来源:gjs-require.cpp

示例4: to_javascript_object

static jsval to_javascript_object(JSContext *context, PyObject *value) {
    if (PyString_Check(value)) {
        JSString *obj = JS_NewStringCopyN(context, PyString_AsString(value), PyString_Size(value));
        return STRING_TO_JSVAL(obj);
    } else if (PyUnicode_Check(value)) {
        PyObject *encoded = PyUnicode_AsUTF8String(value);
        JSString *obj = JS_NewStringCopyN(context, PyString_AsString(encoded), PyString_Size(encoded));
        Py_DECREF(encoded);
        return STRING_TO_JSVAL(obj);
    } else if (PyFloat_Check(value)) {
        return DOUBLE_TO_JSVAL(PyFloat_AsDouble(value));
    } else if (PyInt_Check(value)) {
        return INT_TO_JSVAL(PyInt_AsLong(value));
    } else if (PyLong_Check(value)) {
        return INT_TO_JSVAL(PyLong_AsLong(value));
    } else if (PyList_Check(value)) {
        JSObject *obj = JS_NewArrayObject(context, 0, NULL);
        int i;
        for (i = 0; i < PyList_Size(value); i++) {
            jsval item = to_javascript_object(context, PyList_GetItem(value, i));
            JS_SetElement(context, obj, i, &item);
        }
        return OBJECT_TO_JSVAL(obj);
    } else if (PyTuple_Check(value)) {
        JSObject *obj = JS_NewArrayObject(context, 0, NULL);
        int i;
        for (i = 0; i < PyTuple_Size(value); i++) {
            jsval item = to_javascript_object(context, PyTuple_GetItem(value, i));
            JS_SetElement(context, obj, i, &item);
        }
        return OBJECT_TO_JSVAL(obj);
    } else if (PyDict_Check(value)) {
        JSObject *obj = JS_NewObject(context, NULL, NULL, NULL);
        populate_javascript_object(context, obj, value);
        return OBJECT_TO_JSVAL(obj);
    } else if (PyDateTime_Check(value)) {
        JSObject *obj = JS_NewDateObject(context,
            PyDateTime_GET_YEAR(value),
            PyDateTime_GET_MONTH(value) - 1,
            PyDateTime_GET_DAY(value),
            PyDateTime_DATE_GET_HOUR(value),
            PyDateTime_DATE_GET_MINUTE(value),
            PyDateTime_DATE_GET_SECOND(value));
        return OBJECT_TO_JSVAL(obj);
    } else {
        return JSVAL_NULL;
    }
}
开发者ID:jordanm,项目名称:spindly,代码行数:48,代码来源:spindly.c

示例5: NS_ASSERTION

nsresult
mozilla::dom::bluetooth::StringArrayToJSArray(JSContext* aCx, JSObject* aGlobal,
                                              const nsTArray<nsString>& aSourceArray,
                                              JSObject** aResultArray)
{
  NS_ASSERTION(aCx, "Null context!");
  NS_ASSERTION(aGlobal, "Null global!");

  JSAutoRequest ar(aCx);
  JSAutoEnterCompartment ac;
  if (!ac.enter(aCx, aGlobal)) {
    NS_WARNING("Failed to enter compartment!");
    return NS_ERROR_FAILURE;
  }

  JSObject* arrayObj;

  if (aSourceArray.IsEmpty()) {
    arrayObj = JS_NewArrayObject(aCx, 0, nullptr);
  } else {
    uint32_t valLength = aSourceArray.Length();
    mozilla::ScopedDeleteArray<jsval> valArray(new jsval[valLength]);
    JS::AutoArrayRooter tvr(aCx, valLength, valArray);
    for (PRUint32 index = 0; index < valLength; index++) {
      JSString* s = JS_NewUCStringCopyN(aCx, aSourceArray[index].BeginReading(),
                                        aSourceArray[index].Length());
      if(!s) {
        NS_WARNING("Memory allocation error!");
        return NS_ERROR_OUT_OF_MEMORY;
      }
      valArray[index] = STRING_TO_JSVAL(s);
    }
    arrayObj = JS_NewArrayObject(aCx, valLength, valArray);
  }

  if (!arrayObj) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  // XXX This is not what Jonas wants. He wants it to be live.
  // Followup at bug 717414
  if (!JS_FreezeObject(aCx, arrayObj)) {
    return NS_ERROR_FAILURE;
  }

  *aResultArray = arrayObj;
  return NS_OK;
}
开发者ID:caindove,项目名称:mozilla-central,代码行数:48,代码来源:BluetoothUtils.cpp

示例6: array

nsresult
ArchiveRequest::GetFilesResult(JSContext* aCx,
                               JS::Value* aValue,
                               nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList)
{
  JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, aFileList.Length(), nullptr));
  if (!array) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  for (uint32_t i = 0; i < aFileList.Length(); ++i) {
    nsCOMPtr<nsIDOMFile> file = aFileList[i];

    JS::Rooted<JS::Value> value(aCx);
    JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
    nsresult rv = nsContentUtils::WrapNative(aCx, global, file,
                                             &NS_GET_IID(nsIDOMFile),
                                             value.address());
    if (NS_FAILED(rv) || !JS_SetElement(aCx, array, i, &value)) {
      return NS_ERROR_FAILURE;
    }
  }

  aValue->setObject(*array);
  return NS_OK;
}
开发者ID:Jaxo,项目名称:releases-mozilla-central,代码行数:26,代码来源:ArchiveRequest.cpp

示例7: AfxGlobal_glGenTextures

static JSBool
AfxGlobal_glGenTextures(JSContext *cx, unsigned argc, JS::Value *vp)
{
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
	if(1 > args.length())
		return JS_FALSE;

	uint32_t length;
	if(!JS::ToUint32(cx, args[0], &length))
		return JS_FALSE;

	GLuint * textures = new GLuint[length];
	jsval * jsTextures = new jsval[length];

	glGenTextures(length, textures);

	for(uint32_t i=0; i<length; i++)
	{
		jsTextures[i] = JS_NumberValue(textures[i]);
	}

	delete textures;

	JSObject * retObj = JS_NewArrayObject(cx, length, jsTextures);

	delete jsTextures;

	if(!retObj)
		return JS_FALSE;

	args.rval().set(OBJECT_TO_JSVAL(retObj));

	return JS_TRUE;
}
开发者ID:YaLTeR,项目名称:advancedfx,代码行数:34,代码来源:scripting.cpp

示例8: rpmaug_match

static JSBool
rpmaug_match(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmaugClass, NULL);
    rpmaug aug = ptr;
    JSBool ok = JS_FALSE;
    const char * _path = NULL;
    char ** _matches = NULL;
    int nmatches;

_METHOD_DEBUG_ENTRY(_debug);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &_path)))
        goto exit;

    nmatches = rpmaugMatch(aug, _path, &_matches);
    if (nmatches <= 0) {	/* not found */
	*rval = JSVAL_VOID;
	goto exit;
    } else {
	JSObject *o;
	jsval v;
	int i;
	*rval = OBJECT_TO_JSVAL(o=JS_NewArrayObject(cx, 0, NULL));
	for (i = 0; i < nmatches; i++) {
	    v = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _matches[i]));
	    ok = JS_SetElement(cx, o, i, &v);
	    _matches[i] = _free(_matches[i]);
	}
	_matches = _free(_matches);
    }
    ok = JS_TRUE;
exit:
    return ok;
}
开发者ID:pombredanne,项目名称:tools-yocto1-rpm,代码行数:35,代码来源:rpmaug-js.c

示例9: JSB_glGetSupportedExtensions

// sequence<DOMString>? getSupportedExtensions();
bool JSB_glGetSupportedExtensions(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSB_PRECONDITION2( argc == 0, cx, false, "Invalid number of arguments" );
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    const GLubyte *extensions = glGetString(GL_EXTENSIONS);

    JS::RootedObject jsobj(cx, JS_NewArrayObject(cx, 0));
    JSB_PRECONDITION2(jsobj, cx, false, "Error creating JS Object");

    // copy, to be able to add '\0'
    size_t len = strlen((char*)extensions);
    GLubyte* copy = new (std::nothrow) GLubyte[len+1];
    strncpy((char*)copy, (const char*)extensions, len );

    int start_extension=0;
    int element=0;
    for( size_t i=0; i<len+1; i++) {
        if( copy[i]==' ' || copy[i]==',' || i==len ) {
            copy[i] = 0;

            JS::RootedValue str(cx, charptr_to_jsval(cx, (const char*)&copy[start_extension]));
            JS_SetElement(cx, jsobj, element++, str );

            start_extension = i+1;

            i++;
        }
    }

    args.rval().set(OBJECT_TO_JSVAL(jsobj));
    CC_SAFE_DELETE_ARRAY(copy);
    return true;
    
}
开发者ID:ricardperez,项目名称:Rotallector,代码行数:35,代码来源:jsb_opengl_manual.cpp

示例10: TestTransferObject

bool TestTransferObject()
{
    JS::RootedObject obj1(cx, CreateNewObject(8, 12));
    CHECK(obj1);
    JS::RootedValue v1(cx, JS::ObjectValue(*obj1));

    // Create an Array of transferable values.
    JS::AutoValueVector argv(cx);
    if (!argv.append(v1))
        return false;

    JS::RootedObject obj(cx, JS_NewArrayObject(cx, JS::HandleValueArray::subarray(argv, 0, 1)));
    CHECK(obj);
    JS::RootedValue transferable(cx, JS::ObjectValue(*obj));

    JSAutoStructuredCloneBuffer cloned_buffer(JS::StructuredCloneScope::SameProcessSameThread, nullptr, nullptr);
    CHECK(cloned_buffer.write(cx, v1, transferable, nullptr, nullptr));
    JS::RootedValue v2(cx);
    CHECK(cloned_buffer.read(cx, &v2, nullptr, nullptr));
    JS::RootedObject obj2(cx, v2.toObjectOrNull());
    CHECK(VerifyObject(obj2, 8, 12, true));
    CHECK(JS_IsDetachedArrayBufferObject(obj1));

    return true;
}
开发者ID:cstipkovic,项目名称:gecko-dev,代码行数:25,代码来源:testMappedArrayBuffer.cpp

示例11: NS_ASSERTION

nsresult KeyPath::ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue,
                                    JS::Value* aOutVal) const {
  NS_ASSERTION(IsValid(), "This doesn't make sense!");

  if (IsString()) {
    return GetJSValFromKeyPathString(aCx, aValue, mStrings[0], aOutVal,
                                     DoNotCreateProperties, nullptr, nullptr);
  }

  const uint32_t len = mStrings.Length();
  JS::Rooted<JSObject*> arrayObj(aCx, JS_NewArrayObject(aCx, len));
  if (!arrayObj) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  JS::Rooted<JS::Value> value(aCx);
  for (uint32_t i = 0; i < len; ++i) {
    nsresult rv =
        GetJSValFromKeyPathString(aCx, aValue, mStrings[i], value.address(),
                                  DoNotCreateProperties, nullptr, nullptr);
    if (NS_FAILED(rv)) {
      return rv;
    }

    if (!JS_DefineElement(aCx, arrayObj, i, value, JSPROP_ENUMERATE)) {
      IDB_REPORT_INTERNAL_ERR();
      return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
    }
  }

  aOutVal->setObject(*arrayObj);
  return NS_OK;
}
开发者ID:Noctem,项目名称:gecko-dev,代码行数:33,代码来源:KeyPath.cpp

示例12: JSB_glGetAttachedShaders

// sequence<WebGLShader>? getAttachedShaders(WebGLProgram? program);
JSBool JSB_glGetAttachedShaders(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSB_PRECONDITION2( argc == 1, cx, JS_FALSE, "Invalid number of arguments" );
    jsval *argvp = JS_ARGV(cx,vp);
    JSBool ok = JS_TRUE;
    uint32_t arg0;

    ok &= jsval_to_uint( cx, *argvp++, &arg0 );
    JSB_PRECONDITION2(ok, cx, JS_FALSE, "Error processing arguments");

    GLsizei length;
    glGetProgramiv(arg0, GL_ATTACHED_SHADERS, &length);
    GLuint* buffer = new GLuint[length];
    memset(buffer, 0, length * sizeof(GLuint));
    //Fix bug 2448, it seems that glGetAttachedShaders will crash if we send NULL to the third parameter (eg Windows), same as in lua binding
    GLsizei realShaderCount = 0;
    glGetAttachedShaders(arg0, length, &realShaderCount, buffer);
    
    JSObject *jsobj = JS_NewArrayObject(cx, length, NULL);
    JSB_PRECONDITION2(jsobj, cx, JS_FALSE, "Error creating JS Object");

    for( int i=0; i<length; i++) {
        jsval e = INT_TO_JSVAL(buffer[i]);
        JS_SetElement(cx, jsobj, i, &e );
    }

    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(jsobj));
    CC_SAFE_DELETE_ARRAY(buffer);
    return JS_TRUE;

}
开发者ID:6520874,项目名称:pipiGame,代码行数:32,代码来源:jsb_opengl_manual.cpp

示例13: SMJS_FUNCTION

static JSBool SMJS_FUNCTION(widget_get_interfaces)
{
	u32 i, count;
	char *ifce_name;
	JSObject *list;
	jsuint idx;
	jsval v;
	SMJS_OBJ
	SMJS_ARGS
	GF_WidgetInstance *wid = (GF_WidgetInstance *)SMJS_GET_PRIVATE(c, obj);
	if (!wid) return JS_FALSE;

	if (!argc || !JSVAL_IS_STRING(argv[0])) return JS_TRUE;
	ifce_name = SMJS_CHARS(c, argv[0]);

	list = JS_NewArrayObject(c, 0, 0);

	count = gf_list_count(wid->bound_ifces);
	for (i=0; i<count; i++) {
		GF_WidgetInterfaceInstance *ifce = gf_list_get(wid->bound_ifces, i);
		if (strcmp(ifce->ifce->type, ifce_name)) continue;

		widget_interface_js_bind(c, ifce);

		JS_GetArrayLength(c, list, &idx);
		v = OBJECT_TO_JSVAL(ifce->obj);
		JS_SetElement(c, list, idx, &v);
	}
	SMJS_SET_RVAL( OBJECT_TO_JSVAL(list) );
	SMJS_FREE(c, ifce_name);
	return JS_TRUE;
}
开发者ID:DmitrySigaev,项目名称:gpac_hbbtv,代码行数:32,代码来源:widget.c

示例14: js_cocos2dx_studio_ColliderBody_getCalculatedVertexList

JSBool js_cocos2dx_studio_ColliderBody_getCalculatedVertexList(JSContext *cx, uint32_t argc, jsval *vp)
{
    JSObject *obj = JS_THIS_OBJECT(cx, vp);
    js_proxy_t *proxy = jsb_get_js_proxy(obj);
    cocostudio::ColliderBody* cobj = (cocostudio::ColliderBody *)(proxy ? proxy->ptr : nullptr);
    JSB_PRECONDITION2( cobj, cx, JS_FALSE, "Invalid Native Object");
    if (argc == 0) {
        const std::vector<cocos2d::Point>& ret = cobj->getCalculatedVertexList();
        JSObject *jsretArr = JS_NewArrayObject(cx, 0, nullptr);
        jsval jsret;
        //CCObject* obj;
        int i = 0;
        for(std::vector<cocos2d::Point>::const_iterator it = ret.begin(); it != ret.end(); it++)
        {
            const cocos2d::Point& point = *it;
            JSObject *tmp = JS_NewObject(cx, NULL, NULL, NULL);
            if (!tmp) break;
            JSBool ok = JS_DefineProperty(cx, tmp, "x", DOUBLE_TO_JSVAL(point.x), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT) &&
                JS_DefineProperty(cx, tmp, "y", DOUBLE_TO_JSVAL(point.y), NULL, NULL, JSPROP_ENUMERATE | JSPROP_PERMANENT);
            jsval jsTmp = OBJECT_TO_JSVAL(tmp);
            if(!ok || !JS_SetElement(cx, jsretArr, i, &jsTmp))
            {
                break;
            }
            ++i;
        }
        jsret = OBJECT_TO_JSVAL(jsretArr);
        JS_SET_RVAL(cx, vp, jsret);
        return JS_TRUE;
    }

    JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0);
    return JS_FALSE;
}
开发者ID:6520874,项目名称:pipiGame,代码行数:34,代码来源:jsb_cocos2dx_studio_manual.cpp

示例15: JS_NewArrayObject

JSBool JsIndexer::readMetadataImages(JSContext *cx,JSObject *obj,uintN argc,jsval *argv,jsval *rval)
{
	char *path = {0};

	if ( !JS_ConvertArguments(cx,argc,argv,"s",&path) ) {
		return Engine::throwUsageError(cx,argv);
	}

	std::string utf8Path = path; // the given path should be formatted as utf-8

	// convert utf-8 path to utf-16 since the indexer uses utf-16 internally
	std::wstring utf16Path;
	utf8::utf8to16(utf8Path.begin(),utf8Path.end(),back_inserter(utf16Path));
	
	JSObject *arr = JS_NewArrayObject(cx,0,NULL);
	if ( arr!=NULL )
	{
		int count = 0;

		std::list<MetadataImage::Ptr> images;
		Indexer::getInstance()->readMetadata(utf16Path,NULL,&images);
		for ( std::list<MetadataImage::Ptr>::iterator iter=images.begin(); 
			iter!=images.end(); iter++ )
		{
			jsval element = OBJECT_TO_JSVAL(JsMetadataImage::jsInstance(cx,obj,*iter));
			if ( JS_SetElement(cx,arr,count,&element)==JS_TRUE ) {
				count++;
			}
		}

		*rval = OBJECT_TO_JSVAL(arr);
	}

	return JS_TRUE;
}
开发者ID:CIHANGIRCAN,项目名称:vibestreamer,代码行数:35,代码来源:JsIndexer.cpp


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