本文整理汇总了C++中JS_NewStringCopyN函数的典型用法代码示例。如果您正苦于以下问题:C++ JS_NewStringCopyN函数的具体用法?C++ JS_NewStringCopyN怎么用?C++ JS_NewStringCopyN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了JS_NewStringCopyN函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: FRAGMENT
FRAGMENT(JSString, simple) {
js::Rooted<JSString *> empty(cx, JS_NewStringCopyN(cx, NULL, 0));
js::Rooted<JSString *> x(cx, JS_NewStringCopyN(cx, "x", 1));
js::Rooted<JSString *> z(cx, JS_NewStringCopyZ(cx, "z"));
// I expect this will be a non-inlined string.
js::Rooted<JSString *> stars(cx, JS_NewStringCopyZ(cx,
"*************************"
"*************************"
"*************************"
"*************************"));
// This may well be an inlined string.
js::Rooted<JSString *> xz(cx, JS_ConcatStrings(cx, x, z));
// This will probably be a rope.
js::Rooted<JSString *> doubleStars(cx, JS_ConcatStrings(cx, stars, stars));
breakpoint();
(void) empty;
(void) x;
(void) z;
(void) stars;
(void) xz;
(void) doubleStars;
}
开发者ID:mshal,项目名称:mozilla-central,代码行数:27,代码来源:test-JSString.cpp
示例2: FRAGMENT
FRAGMENT(JSString, simple) {
AutoSuppressHazardsForTest noanalysis;
JS::Rooted<JSString*> empty(cx, JS_NewStringCopyN(cx, nullptr, 0));
JS::Rooted<JSString*> x(cx, JS_NewStringCopyN(cx, "x", 1));
JS::Rooted<JSString*> z(cx, JS_NewStringCopyZ(cx, "z"));
// I expect this will be a non-inlined string.
JS::Rooted<JSString*> stars(cx,
JS_NewStringCopyZ(cx,
"*************************"
"*************************"
"*************************"
"*************************"));
// This may well be an inlined string.
JS::Rooted<JSString*> xz(cx, JS_ConcatStrings(cx, x, z));
// This will probably be a rope.
JS::Rooted<JSString*> doubleStars(cx, JS_ConcatStrings(cx, stars, stars));
// Ensure we're not confused by typedefs for pointer types.
JSString* xRaw = x;
breakpoint();
use(empty);
use(x);
use(z);
use(stars);
use(xz);
use(doubleStars);
use(xRaw);
}
开发者ID:servo,项目名称:mozjs,代码行数:34,代码来源:test-JSString.cpp
示例3: 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
示例4: rq
void CStdDeserializer::ScriptString(const char* name, JS::MutableHandleString out)
{
#if BYTE_ORDER != LITTLE_ENDIAN
#error TODO: probably need to convert JS strings from little-endian
#endif
JSContext* cx = m_ScriptInterface.GetContext();
JSAutoRequest rq(cx);
bool isLatin1;
Bool("isLatin1", isLatin1);
if (isLatin1)
{
std::vector<JS::Latin1Char> str;
ReadStringLatin1(name, str);
out.set(JS_NewStringCopyN(cx, (const char*)str.data(), str.size()));
if (!out)
throw PSERROR_Deserialize_ScriptError("JS_NewStringCopyN failed");
}
else
{
utf16string str;
ReadStringUTF16(name, str);
out.set(JS_NewUCStringCopyN(cx, (const char16_t*)str.data(), str.length()));
if (!out)
throw PSERROR_Deserialize_ScriptError("JS_NewUCStringCopyN failed");
}
}
开发者ID:2asoft,项目名称:0ad,代码行数:30,代码来源:StdDeserializer.cpp
示例5: JS_NewArrayObject
JSBool JsSite::getAttributeNames(JSContext *cx,JSObject *obj,uintN argc,jsval *argv,jsval *rval)
{
Site *site = (Site*)JS_GetPrivate(cx,obj);
JSObject *arr = JS_NewArrayObject(cx,0,NULL);
if ( arr!=NULL )
{
int count=0;
std::map<std::string,std::string> attributes = site->getAttributes();
std::map<std::string,std::string>::const_iterator iter;
for ( iter=attributes.begin(); iter!=attributes.end(); iter++ )
{
JSString *str = JS_NewStringCopyN(cx,iter->first.c_str(),iter->first.length());
jsval element = STRING_TO_JSVAL(str);
if ( JS_SetElement(cx,arr,count,&element)==JS_TRUE ) {
count++;
}
}
*rval = OBJECT_TO_JSVAL(arr);
}
return JS_TRUE;
}
开发者ID:CIHANGIRCAN,项目名称:vibestreamer,代码行数:25,代码来源:JsSite.cpp
示例6: Atob
Atob(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSString *str;
if (!argc)
return JS_TRUE;
str = JS_ValueToString(cx, argv[0]);
if (!str)
return JS_FALSE;
size_t base64StrLength = JS_GetStringLength(str);
char *base64Str = JS_GetStringBytes(str);
PRUint32 bin_dataLength = (PRUint32)base64StrLength;
if (base64Str[base64StrLength - 1] == '=') {
if (base64Str[base64StrLength - 2] == '=')
bin_dataLength -= 2;
else
--bin_dataLength;
}
bin_dataLength = (PRUint32)((PRUint64)bin_dataLength * 3) / 4;
char *bin_data = PL_Base64Decode(base64Str, base64StrLength, nsnull);
if (!bin_data)
return JS_FALSE;
str = JS_NewStringCopyN(cx, bin_data, bin_dataLength);
PR_Free(bin_data);
if (!str)
return JS_FALSE;
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:34,代码来源:mozJSComponentLoader.cpp
示例7: Btoa
Btoa(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
JSString *str;
if (!argc)
return JS_TRUE;
str = JS_ValueToString(cx, argv[0]);
if (!str)
return JS_FALSE;
char *bin_data = JS_GetStringBytes(str);
size_t bin_dataLength = JS_GetStringLength(str);
char *base64 = PL_Base64Encode(bin_data, bin_dataLength, nsnull);
if (!base64)
return JS_FALSE;
PRUint32 base64Length = ((bin_dataLength + 2) / 3) * 4;
str = JS_NewStringCopyN(cx, base64, base64Length);
PR_Free(base64);
if (!str)
return JS_FALSE;
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:26,代码来源:mozJSComponentLoader.cpp
示例8: add_module_property_to_module_scope
static JSObject *
add_module_property_to_module_scope (JSContext *cx,
JSObject *scope,
const gchar *module_id)
{
JSObject *module;
jsval value;
JSString *st;
JSAutoCompartment ac(cx, scope);
/* create the 'module' object */
module = JS_NewObject (cx, NULL, NULL, NULL);
g_assert (module != NULL);
/* add 'module' object as property of scope */
value = OBJECT_TO_JSVAL (module);
g_assert (JS_SetProperty (cx, scope, "module", &value));
/* make 'exports' a permanent and read-only property of scope */
seal_object_property (cx, scope, "module");
/* add 'id' property to module object */
st = JS_NewStringCopyN (cx, module_id, strlen (module_id));
value = STRING_TO_JSVAL (st);
g_assert (JS_SetProperty (cx, module, "id", &value));
/* freeze module object */
JS_FreezeObject (cx, module);
return module;
}
开发者ID:groleo,项目名称:gjs-commonjs,代码行数:31,代码来源:gjs-require.cpp
示例9: file_callback
static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
{
register unsigned int realsize = (unsigned int) (size * nmemb);
struct curl_obj *co = data;
uintN argc = 0;
jsval argv[4];
if (!co) {
return 0;
}
if (co->function) {
char *ret;
argv[argc++] = STRING_TO_JSVAL(JS_NewStringCopyN(co->cx, (char *) ptr, realsize));
if (co->user_data) {
argv[argc++] = OBJECT_TO_JSVAL(co->user_data);
}
JS_ResumeRequest(co->cx, co->saveDepth);
JS_CallFunction(co->cx, co->obj, co->function, argc, argv, &co->ret);
co->saveDepth = JS_SuspendRequest(co->cx);
if ((ret = JS_GetStringBytes(JS_ValueToString(co->cx, co->ret)))) {
if (!strcmp(ret, "true") || !strcmp(ret, "undefined")) {
return realsize;
} else {
return 0;
}
}
}
return realsize;
}
开发者ID:PauloFer1,项目名称:FreeSWITCH,代码行数:32,代码来源:mod_spidermonkey_curl.c
示例10: JS_NewStringCopyN
template<> jsval ScriptInterface::ToJSVal<std::string>(JSContext* cx, const std::string& val)
{
JSString* str = JS_NewStringCopyN(cx, val.c_str(), val.length());
if (str)
return STRING_TO_JSVAL(str);
return JSVAL_VOID;
}
开发者ID:Valvador,项目名称:PyroSpaceFork,代码行数:7,代码来源:ScriptConversions.cpp
示例11: jsGetParity
static JSBool
jsGetParity( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
jsPort_t *port = (jsPort_t *)JS_GetInstancePrivate( cx, obj, &jsSerialPortClass_, NULL );
if( port )
{
struct termios oldTermState;
tcgetattr(port->getFd(),&oldTermState);
char const *parity ;
if( oldTermState.c_cflag & PARENB )
{
if( oldTermState.c_cflag & PARODD )
parity = "O" ;
else
parity = "E" ;
}
else
parity = "N" ;
*rval = STRING_TO_JSVAL( JS_NewStringCopyN( cx, parity, 1 ) );
}
else
*rval = JSVAL_FALSE ;
return JS_TRUE ;
}
开发者ID:boundarydevices,项目名称:bdScript,代码行数:26,代码来源:jsSerial.cpp
示例12: NewAddonId
JSAddonId*
NewAddonId(JSContext* cx, const nsACString& id)
{
JS::RootedString str(cx, JS_NewStringCopyN(cx, id.BeginReading(), id.Length()));
if (!str)
return nullptr;
return JS::NewAddonId(cx, str);
}
开发者ID:cstipkovic,项目名称:spidermonkey-research,代码行数:8,代码来源:nsXPConnect.cpp
示例13: JS_NewStringCopyN
JSBool JsSite::getPath(JSContext *cx,JSObject *obj,uintN argc,jsval *argv,jsval *rval)
{
Site *site = (Site*)JS_GetPrivate(cx,obj);
JSString *str = JS_NewStringCopyN(cx,site->getPath().c_str(),site->getPath().length());
*rval = STRING_TO_JSVAL(str);
return JS_TRUE;
}
开发者ID:CIHANGIRCAN,项目名称:vibestreamer,代码行数:8,代码来源:JsSite.cpp
示例14: rq
template<> void ScriptInterface::ToJSVal<std::string>(JSContext* cx, JS::MutableHandleValue ret, const std::string& val)
{
JSAutoRequest rq(cx);
JS::RootedString str(cx, JS_NewStringCopyN(cx, val.c_str(), val.length()));
if (str)
ret.setString(str);
else
ret.setUndefined();
}
开发者ID:krichter722,项目名称:0ad,代码行数:9,代码来源:ScriptConversions.cpp
示例15: livemarkInfoToJSVal
// This is a temporary converter used by nsPlacesImportExportService until
// bug 482911 completes its js rewrite.
jsval
livemarkInfoToJSVal(PRInt64 aId,
const nsACString& aGUID,
const nsAString& aTitle,
PRInt64 aParentId,
PRInt32 aIndex,
nsCOMPtr<nsIURI>& aFeedURI,
nsCOMPtr<nsIURI>& aSiteURI)
{
nsCOMPtr<nsIXPConnect> xpc = mozilla::services::GetXPConnect();
NS_ENSURE_TRUE(xpc, JSVAL_NULL);
nsAXPCNativeCallContext *ncc;
nsresult rv = xpc->GetCurrentNativeCallContext(&ncc);
NS_ENSURE_SUCCESS(rv, JSVAL_NULL);
JSContext *cx = nsnull;
rv = ncc->GetJSContext(&cx);
NS_ENSURE_SUCCESS(rv, JSVAL_NULL);
JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
NS_ENSURE_TRUE(obj, JSVAL_NULL);
jsval id;
NS_ENSURE_TRUE(JS_NewNumberValue(cx, double(aId), &id), JSVAL_NULL);
JSString* guid = JS_NewStringCopyN(cx, PromiseFlatCString(aGUID).get(),
aGUID.Length());
NS_ENSURE_TRUE(guid, JSVAL_NULL);
JSString* title = JS_NewUCStringCopyN(cx, PromiseFlatString(aTitle).get(),
aTitle.Length());
NS_ENSURE_TRUE(title, JSVAL_NULL);
jsval parentId;
NS_ENSURE_TRUE(JS_NewNumberValue(cx, double(aParentId), &parentId), JSVAL_NULL);
jsval feedURI;
rv = nsContentUtils::WrapNative(cx, JS_GetGlobalForScopeChain(cx),
NS_ISUPPORTS_CAST(nsIURI*, aFeedURI), &feedURI);
NS_ENSURE_SUCCESS(rv, JSVAL_NULL);
jsval siteURI;
rv = nsContentUtils::WrapNative(cx, JS_GetGlobalForScopeChain(cx),
NS_ISUPPORTS_CAST(nsIURI*, aSiteURI), &siteURI);
NS_ENSURE_SUCCESS(rv, JSVAL_NULL);
if (!JS_DefineProperty(cx, obj, "id", id, NULL, NULL, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, obj, "guid", STRING_TO_JSVAL(guid), NULL, NULL, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, obj, "title", STRING_TO_JSVAL(title), NULL, NULL, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, obj, "parentId", parentId, NULL, NULL, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, obj, "index", INT_TO_JSVAL(aIndex), NULL, NULL, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, obj, "feedURI", feedURI, NULL, NULL, JSPROP_ENUMERATE) ||
!JS_DefineProperty(cx, obj, "siteURI", siteURI, NULL, NULL, JSPROP_ENUMERATE)) {
return JSVAL_NULL;
}
return OBJECT_TO_JSVAL(obj);
}
开发者ID:Anachid,项目名称:mozilla-central,代码行数:58,代码来源:Helpers.cpp
示例16: JSTranslate
/**
* The function used as ZOOTranslate from the JavaScript environment.
* Use the ZOO-Services messages translation function from the Python
* environment (ZOO-API)
*
* @param cx the JavaScript context
* @param argc the number of parameters
* @param argv1 the parameter values
* @return true
*/
JSBool
JSTranslate(JSContext *cx, uintN argc, jsval *argv1)
{
jsval *argv = JS_ARGV(cx,argv1);
char *str=JSValToChar(cx,&argv[0]);
char *tmpValue=_ss(str);
JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpValue,strlen(tmpValue))));
JS_MaybeGC(cx);
return JS_TRUE;
}
开发者ID:OSGeo,项目名称:zoo-project,代码行数:20,代码来源:service_internal_js.c
示例17: CharacterDataHandler
static void
CharacterDataHandler(void *userdata, const char *s, int len)
{
XMLGraphCallback *cb = (XMLGraphCallback *)userdata;
JSString *str;
JSContext *cx = cb->cb.cx;
str = JS_NewStringCopyN(cx, s, len);
if (!str)
return;
JS_DefineProperty(cx, cb->current, "__cdata__", STRING_TO_JSVAL(str),
NULL, NULL, 0);
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:13,代码来源:jsxgraph.c
示例18: push_path_to_array
static void
push_path_to_array (JSContext *cx, JSObject *paths, const gchar *path)
{
jsval val;
JSString *st;
guint len;
JSAutoCompartment ac(cx, paths);
st = JS_NewStringCopyN (cx, path, strlen (path));
val = STRING_TO_JSVAL (st);
JS_GetArrayLength(cx, paths, &len);
JS_SetElement (cx, paths, len, &val);
}
开发者ID:groleo,项目名称:gjs-commonjs,代码行数:14,代码来源:gjs-require.cpp
示例19: ToJSString
static bool
ToJSString(JSContext* aCx, GMPMediaKeyStatus aStatus,
JS::MutableHandle<JS::Value> aResult)
{
auto val = uint32_t(ToMediaKeyStatus(aStatus));
MOZ_ASSERT(val < ArrayLength(MediaKeyStatusValues::strings));
JSString* str = JS_NewStringCopyN(aCx,
MediaKeyStatusValues::strings[val].value,
MediaKeyStatusValues::strings[val].length);
if (!str) {
return false;
}
aResult.setString(str);
return true;
}
开发者ID:70599,项目名称:Waterfox,代码行数:15,代码来源:MediaKeyStatusMap.cpp
示例20: jsCurrentURL
static JSBool
jsCurrentURL( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval )
{
JSString *jsCurrent = 0 ;
std::string current ;
if( currentURL( current ) )
{
jsCurrent = JS_NewStringCopyN( cx, current.c_str(), current.size() );
}
else
jsCurrent = JS_NewStringCopyZ( cx, "unknown" );
*rval = STRING_TO_JSVAL( jsCurrent );
return JS_TRUE ;
}
开发者ID:boundarydevices,项目名称:bdScript,代码行数:16,代码来源:jsURL.cpp
注:本文中的JS_NewStringCopyN函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论