add jsstring to jsval conversion macro that copes with null jsstrings

This commit is contained in:
Vincent Sanders 2012-11-03 17:37:59 +00:00
parent e0f17a8d35
commit 85c973f986
2 changed files with 17 additions and 0 deletions

View File

@ -94,6 +94,8 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
outchar = JS_GetStringBytes(injsstring); \
outlen = strlen(outchar)
/* string type cast */
#define JSAPI_STRING_TO_JSVAL(str) ((str == NULL)?JSVAL_NULL:STRING_TO_JSVAL(str))
#else /* #if JS_VERSION <= 180 */
@ -152,6 +154,8 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
JS_EncodeStringToBuffer(injsstring, outchar, outlen); \
outchar[outlen] = '\0'
/* string type cast */
#define JSAPI_STRING_TO_JSVAL(str) ((str == NULL)?JSVAL_NULL:STRING_TO_JSVAL(str))
#endif

13
test/js/dom-location.html Normal file
View File

@ -0,0 +1,13 @@
<html>
<head>
<title>Assign window.lately</title>
<link rel="stylesheet" type="text/css" href="tst.css">
</head>
<body>
<h1>Assign window.lately</h1>
<p>location: <script>document.write(location);</script>
<p>location.protocol: <script>document.write(location.protocol);</script>
<p>equivalence <script>document.write(location.protocol === 'http:');</script>
<p>assignement<script>window.lately = (location.protocol === 'http:');</script>
</body>
</html>