[gjs] Initialize SpiderMonkey Parser API



commit 93da7231f1d52bfc240140f7c67f6cd18dc7fdb0
Author: Sebastien Lafargue <slaf66 gmail com>
Date:   Wed Jul 17 14:58:27 2013 +0200

    Initialize SpiderMonkey Parser API
    
    we can now use the Reflect.parse() method for parsing JavaScript code
    https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
    
    https://bugzilla.gnome.org/show_bug.cgi?id=704406

 Makefile-insttest.am                    |    1 +
 gjs/context.c                           |    3 +++
 installed-tests/js/testReflectObject.js |   15 +++++++++++++++
 3 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-insttest.am b/Makefile-insttest.am
index 2e18c58..eb80052 100644
--- a/Makefile-insttest.am
+++ b/Makefile-insttest.am
@@ -106,6 +106,7 @@ dist_jstests_DATA += \
        installed-tests/js/testMainloop.js                      \
        installed-tests/js/testMetaClass.js                     \
        installed-tests/js/testParamSpec.js                     \
+       installed-tests/js/testReflectObject.js                 \
        installed-tests/js/testSignals.js                       \
        installed-tests/js/testSystem.js                        \
        installed-tests/js/testTweener.js                       \
diff --git a/gjs/context.c b/gjs/context.c
index 120ae96..c9353d7 100644
--- a/gjs/context.c
+++ b/gjs/context.c
@@ -630,6 +630,9 @@ gjs_context_constructor (GType                  type,
                            JSPROP_READONLY | JSPROP_PERMANENT))
         g_error("No memory to export global object as 'window'");
 
+    if (!JS_InitReflect(js_context->context, js_context->global))
+        g_error("Failed to register Reflect Parser Api");
+
     /* Define a global function called log() */
     if (!JS_DefineFunction(js_context->context, js_context->global,
                            "log",
diff --git a/installed-tests/js/testReflectObject.js b/installed-tests/js/testReflectObject.js
new file mode 100644
index 0000000..a338e3a
--- /dev/null
+++ b/installed-tests/js/testReflectObject.js
@@ -0,0 +1,15 @@
+// application/javascript;version=1.8
+const JSUnit = imports.jsUnit;
+
+function testReflect() {
+    JSUnit.assertTrue(Reflect.parse instanceof Function);
+
+    var expr = Reflect.parse("var a = 10;");
+
+    JSUnit.assertEquals("Program", expr.type);
+    JSUnit.assertEquals("VariableDeclaration", expr.body[0].type);
+    JSUnit.assertEquals("a",expr.body[0].declarations[0].id.name);
+    JSUnit.assertEquals(10,expr.body[0].declarations[0].init.value);
+}
+
+JSUnit.gjstestRun(this, JSUnit.setUp, JSUnit.tearDown);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]