6 Javascript instance = null;
8 public class Javascript {
11 public static JSCore.Object class_constructor(
13 JSCore.Object constructor,
14 JSCore.Value[] arguments,
15 out JSCore.Value exception)
17 var c = new JSCore.Class (class_definition);
18 var o = new JSCore.Object (ctx, c, null);
22 static const JSCore.StaticFunction[] class_functions = {
25 static const JSCore.ClassDefinition class_definition = {
27 JSCore.ClassAttribute.None,
50 public JSCore.GlobalContext js_global_context = null;
52 public static Javascript singleton()
54 if (instance == null) {
55 instance = new Javascript();
61 var goc = new JSCore.Class( class_definition );
62 this.js_global_context = new JSCore.GlobalContext(goc);
66 public int validate(string code, out string res)
69 unowned JSCore.GlobalContext ctx = this.js_global_context;
70 var ret = this.js_global_context.check_script_syntax(
71 new JSCore.String.with_utf8_c_string(code),
77 if (ex.is_null(ctx)) {
82 var exo = ex.to_object(ctx, null);
83 unowned JSCore.PropertyNameArray property_names = exo.copy_property_names (ctx);
88 var js_string = new JSCore.String.with_utf8_c_string("line");
89 var line = exo.get_property(ctx, js_string, null).to_number(ctx,null);
93 // see if we can convert exception string
94 char *c_string = new char[1024];
95 var err_string = ex.to_string_copy (ctx, null);
96 err_string.get_utf8_c_string (c_string, 1023);
97 res = (string)c_string;
98 //print ("Error on line %d\n%s\n", (int)line, res);
100 var rline = (int) line;
102 return rline > 0 ? rline -1 : 0;