[javascriptlint-commit] SF.net SVN: javascriptlint:[291] trunk
Status: Beta
Brought to you by:
matthiasmiller
|
From: <mat...@us...> - 2009-11-18 12:07:08
|
Revision: 291
http://javascriptlint.svn.sourceforge.net/javascriptlint/?rev=291&view=rev
Author: matthiasmiller
Date: 2009-11-18 12:06:56 +0000 (Wed, 18 Nov 2009)
Log Message:
-----------
#2890901: Support Unicode characters in scripts.
Modified Paths:
--------------
trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c
trunk/spidermonkey/src/jsapi.c
trunk/spidermonkey/src/jsapi.h
Added Paths:
-----------
trunk/tests/bugs/
Modified: trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c
===================================================================
--- trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c 2009-11-18 11:11:00 UTC (rev 290)
+++ trunk/javascriptlint/pyspidermonkey/pyspidermonkey.c 2009-11-18 12:06:56 UTC (rev 291)
@@ -19,7 +19,6 @@
#define ARRAY_COUNT(a) (sizeof(a) / sizeof(a[0]))
-
/** CONSTANTS
*/
static const char* tokens[] = {
@@ -47,7 +46,21 @@
#define TOK_TO_NUM(tok) (tok+1000)
#define OPCODE_TO_NUM(op) (op+2000)
+static jschar*
+tojschar(const char* buf) {
+ return (jschar*)buf;
+}
+static int
+tojscharlen(int buflen) {
+ /* The buffer length shouldn't be an odd number, buf if it is, the buffer
+ will be truncated to exclude it.
+ */
+ JS_STATIC_ASSERT(sizeof(char) == 1);
+ JS_STATIC_ASSERT(sizeof(jschar) == 2);
+ return buflen / 2;
+}
+
/** MODULE INITIALIZATION
*/
@@ -415,7 +428,8 @@
static PyObject*
module_parse(PyObject *self, PyObject *args) {
struct {
- const char* script;
+ char* scriptbuf;
+ int scriptbuflen;
PyObject* pynode;
JSRuntime* runtime;
@@ -423,7 +437,6 @@
JSObject* global;
JSTokenStream* token_stream;
JSParseNode* jsnode;
- JSString* contents;
JSContextData ctx_data;
} m;
@@ -433,9 +446,9 @@
error = "encountered an unknown error";
/* validate arguments */
- if (!PyArg_ParseTuple(args, "sOOll", &m.script, &m.ctx_data.node_class,
- &m.ctx_data.error_callback, &m.ctx_data.first_lineno,
- &m.ctx_data.first_index)) {
+ if (!PyArg_ParseTuple(args, "es#OOll", "utf16", &m.scriptbuf,
+ &m.scriptbuflen, &m.ctx_data.node_class, &m.ctx_data.error_callback,
+ &m.ctx_data.first_lineno, &m.ctx_data.first_index)) {
return NULL;
}
@@ -453,13 +466,8 @@
if (error)
goto cleanup;
- m.contents = JS_NewStringCopyZ(m.context, m.script);
- if (m.contents == NULL) {
- error = "cannot create script contents";
- goto cleanup;
- }
-
- m.token_stream = js_NewBufferTokenStream(m.context, JS_GetStringChars(m.contents), JS_GetStringLength(m.contents));
+ m.token_stream = js_NewBufferTokenStream(m.context, tojschar(m.scriptbuf),
+ tojscharlen(m.scriptbuflen));
if (!m.token_stream) {
error = "cannot create token stream";
goto cleanup;
@@ -486,6 +494,8 @@
JS_DestroyContext(m.context);
if (m.runtime)
JS_DestroyRuntime(m.runtime);
+ if (m.scriptbuf)
+ PyMem_Free(m.scriptbuf);
if (error) {
if (*error) {
@@ -499,7 +509,8 @@
static PyObject*
is_compilable_unit(PyObject *self, PyObject *args) {
struct {
- const char* script;
+ char* scriptbuf;
+ int scriptbuflen;
JSRuntime* runtime;
JSContext* context;
JSObject* global;
@@ -510,15 +521,16 @@
memset(&m, 0, sizeof(m));
error = "encountered an unknown error";
- if (!PyArg_ParseTuple(args, "s", &m.script))
+ if (!PyArg_ParseTuple(args, "es#", "utf16", &m.scriptbuf, &m.scriptbuflen))
return NULL;
error = create_jscontext(NULL, &m.runtime, &m.context, &m.global);
if (error)
goto cleanup;
- m.is_compilable = JS_BufferIsCompilableUnit(m.context, m.global,
- m.script, strlen(m.script));
+ m.is_compilable = JS_UCBufferIsCompilableUnit(m.context, m.global,
+ tojschar(m.scriptbuf),
+ tojscharlen(m.scriptbuflen));
error = NULL;
cleanup:
@@ -526,6 +538,8 @@
JS_DestroyContext(m.context);
if (m.runtime)
JS_DestroyRuntime(m.runtime);
+ if (m.scriptbuf)
+ PyMem_Free(m.scriptbuf);
if (error) {
if (*error)
Modified: trunk/spidermonkey/src/jsapi.c
===================================================================
--- trunk/spidermonkey/src/jsapi.c 2009-11-18 11:11:00 UTC (rev 290)
+++ trunk/spidermonkey/src/jsapi.c 2009-11-18 12:06:56 UTC (rev 291)
@@ -3877,15 +3877,28 @@
{
jschar *chars;
JSBool result;
+
+ CHECK_REQUEST(cx);
+ chars = js_InflateString(cx, bytes, &length);
+ if (!chars)
+ return JS_TRUE;
+
+ result = JS_UCBufferIsCompilableUnit(cx, obj, chars, length);
+ JS_free(cx, chars);
+ return result;
+}
+
+JS_PUBLIC_API(JSBool)
+JS_UCBufferIsCompilableUnit(JSContext *cx, JSObject *obj,
+ const jschar *chars, size_t length)
+{
+ JSBool result;
JSExceptionState *exnState;
void *tempMark;
JSTokenStream *ts;
JSErrorReporter older;
CHECK_REQUEST(cx);
- chars = js_InflateString(cx, bytes, &length);
- if (!chars)
- return JS_TRUE;
/*
* Return true on any out-of-memory error, so our caller doesn't try to
@@ -3912,7 +3925,6 @@
JS_ARENA_RELEASE(&cx->tempPool, tempMark);
}
- JS_free(cx, chars);
JS_RestoreExceptionState(cx, exnState);
return result;
}
Modified: trunk/spidermonkey/src/jsapi.h
===================================================================
--- trunk/spidermonkey/src/jsapi.h 2009-11-18 11:11:00 UTC (rev 290)
+++ trunk/spidermonkey/src/jsapi.h 2009-11-18 12:06:56 UTC (rev 291)
@@ -1606,6 +1606,10 @@
JS_BufferIsCompilableUnit(JSContext *cx, JSObject *obj,
const char *bytes, size_t length);
+JS_PUBLIC_API(JSBool)
+JS_UCBufferIsCompilableUnit(JSContext *cx, JSObject *obj,
+ const jschar *chars, size_t length);
+
/*
* The JSScript objects returned by the following functions refer to string and
* other kinds of literals, including doubles and RegExp objects. These
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|