johnson 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +14 -0
- data/CHANGELOG.rdoc +11 -0
- data/Manifest.txt +370 -0
- data/README.rdoc +60 -0
- data/Rakefile +42 -0
- data/bin/johnson +108 -0
- data/docs/MINGW32.mk +124 -0
- data/docs/cross-compile.txt +38 -0
- data/ext/spidermonkey/context.c +115 -0
- data/ext/spidermonkey/context.h +19 -0
- data/ext/spidermonkey/conversions.c +320 -0
- data/ext/spidermonkey/conversions.h +18 -0
- data/ext/spidermonkey/debugger.c +226 -0
- data/ext/spidermonkey/debugger.h +9 -0
- data/ext/spidermonkey/extconf.rb +30 -0
- data/ext/spidermonkey/extensions.c +37 -0
- data/ext/spidermonkey/extensions.h +12 -0
- data/ext/spidermonkey/global.c +40 -0
- data/ext/spidermonkey/global.h +11 -0
- data/ext/spidermonkey/idhash.c +16 -0
- data/ext/spidermonkey/idhash.h +8 -0
- data/ext/spidermonkey/immutable_node.c +1153 -0
- data/ext/spidermonkey/immutable_node.c.erb +523 -0
- data/ext/spidermonkey/immutable_node.h +22 -0
- data/ext/spidermonkey/jroot.h +187 -0
- data/ext/spidermonkey/js_land_proxy.c +610 -0
- data/ext/spidermonkey/js_land_proxy.h +20 -0
- data/ext/spidermonkey/ruby_land_proxy.c +543 -0
- data/ext/spidermonkey/ruby_land_proxy.h +17 -0
- data/ext/spidermonkey/runtime.c +330 -0
- data/ext/spidermonkey/runtime.h +25 -0
- data/ext/spidermonkey/spidermonkey.c +20 -0
- data/ext/spidermonkey/spidermonkey.h +29 -0
- data/johnson.gemspec +44 -0
- data/js/johnson/cli.js +30 -0
- data/js/johnson/prelude.js +80 -0
- data/lib/johnson.rb +55 -0
- data/lib/johnson/cli.rb +7 -0
- data/lib/johnson/cli/options.rb +67 -0
- data/lib/johnson/error.rb +4 -0
- data/lib/johnson/nodes.rb +7 -0
- data/lib/johnson/nodes/binary_node.rb +65 -0
- data/lib/johnson/nodes/for.rb +14 -0
- data/lib/johnson/nodes/for_in.rb +12 -0
- data/lib/johnson/nodes/function.rb +13 -0
- data/lib/johnson/nodes/list.rb +28 -0
- data/lib/johnson/nodes/node.rb +68 -0
- data/lib/johnson/nodes/ternary_node.rb +20 -0
- data/lib/johnson/parser.rb +21 -0
- data/lib/johnson/parser/syntax_error.rb +13 -0
- data/lib/johnson/runtime.rb +63 -0
- data/lib/johnson/spidermonkey/context.rb +10 -0
- data/lib/johnson/spidermonkey/debugger.rb +67 -0
- data/lib/johnson/spidermonkey/immutable_node.rb +282 -0
- data/lib/johnson/spidermonkey/js_land_proxy.rb +62 -0
- data/lib/johnson/spidermonkey/mutable_tree_visitor.rb +242 -0
- data/lib/johnson/spidermonkey/ruby_land_proxy.rb +54 -0
- data/lib/johnson/spidermonkey/runtime.rb +103 -0
- data/lib/johnson/version.rb +3 -0
- data/lib/johnson/visitable.rb +16 -0
- data/lib/johnson/visitors.rb +5 -0
- data/lib/johnson/visitors/dot_visitor.rb +169 -0
- data/lib/johnson/visitors/ecma_visitor.rb +323 -0
- data/lib/johnson/visitors/enumerating_visitor.rb +15 -0
- data/lib/johnson/visitors/sexp_visitor.rb +174 -0
- data/lib/johnson/visitors/visitor.rb +91 -0
- data/lib/rails/init.rb +37 -0
- data/lib/tasks/gem.rake +9 -0
- data/lib/tasks/parsing.rake +37 -0
- data/lib/tasks/testing.rake +36 -0
- data/lib/tasks/vendor.rake +20 -0
- data/test/helper.rb +55 -0
- data/test/johnson/browser_test.rb +43 -0
- data/test/johnson/conversions/array_test.rb +32 -0
- data/test/johnson/conversions/boolean_test.rb +17 -0
- data/test/johnson/conversions/callable_test.rb +34 -0
- data/test/johnson/conversions/file_test.rb +15 -0
- data/test/johnson/conversions/nil_test.rb +20 -0
- data/test/johnson/conversions/number_test.rb +34 -0
- data/test/johnson/conversions/regexp_test.rb +24 -0
- data/test/johnson/conversions/string_test.rb +26 -0
- data/test/johnson/conversions/struct_test.rb +15 -0
- data/test/johnson/conversions/symbol_test.rb +19 -0
- data/test/johnson/conversions/thread_test.rb +24 -0
- data/test/johnson/error_test.rb +9 -0
- data/test/johnson/extensions_test.rb +56 -0
- data/test/johnson/nodes/array_literal_test.rb +57 -0
- data/test/johnson/nodes/array_node_test.rb +26 -0
- data/test/johnson/nodes/binary_node_test.rb +61 -0
- data/test/johnson/nodes/bracket_access_test.rb +16 -0
- data/test/johnson/nodes/delete_test.rb +11 -0
- data/test/johnson/nodes/do_while_test.rb +12 -0
- data/test/johnson/nodes/dot_accessor_test.rb +15 -0
- data/test/johnson/nodes/export_test.rb +9 -0
- data/test/johnson/nodes/for_test.rb +54 -0
- data/test/johnson/nodes/function_test.rb +71 -0
- data/test/johnson/nodes/if_test.rb +41 -0
- data/test/johnson/nodes/import_test.rb +13 -0
- data/test/johnson/nodes/label_test.rb +19 -0
- data/test/johnson/nodes/let_test.rb +31 -0
- data/test/johnson/nodes/object_literal_test.rb +110 -0
- data/test/johnson/nodes/return_test.rb +16 -0
- data/test/johnson/nodes/semi_test.rb +8 -0
- data/test/johnson/nodes/switch_test.rb +55 -0
- data/test/johnson/nodes/ternary_test.rb +25 -0
- data/test/johnson/nodes/throw_test.rb +9 -0
- data/test/johnson/nodes/try_node_test.rb +59 -0
- data/test/johnson/nodes/typeof_test.rb +11 -0
- data/test/johnson/nodes/unary_node_test.rb +23 -0
- data/test/johnson/nodes/void_test.rb +11 -0
- data/test/johnson/nodes/while_test.rb +26 -0
- data/test/johnson/nodes/with_test.rb +10 -0
- data/test/johnson/prelude_test.rb +56 -0
- data/test/johnson/runtime_test.rb +64 -0
- data/test/johnson/spidermonkey/context_test.rb +21 -0
- data/test/johnson/spidermonkey/immutable_node_test.rb +34 -0
- data/test/johnson/spidermonkey/js_land_proxy_test.rb +236 -0
- data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +240 -0
- data/test/johnson/spidermonkey/runtime_test.rb +17 -0
- data/test/johnson/version_test.rb +13 -0
- data/test/johnson/visitors/dot_visitor_test.rb +39 -0
- data/test/johnson/visitors/enumerating_visitor_test.rb +12 -0
- data/test/johnson_test.rb +16 -0
- data/test/parser_test.rb +276 -0
- data/vendor/spidermonkey/.cvsignore +9 -0
- data/vendor/spidermonkey/Makefile.in +449 -0
- data/vendor/spidermonkey/Makefile.ref +365 -0
- data/vendor/spidermonkey/README.html +820 -0
- data/vendor/spidermonkey/SpiderMonkey.rsp +12 -0
- data/vendor/spidermonkey/Y.js +19 -0
- data/vendor/spidermonkey/build.mk +43 -0
- data/vendor/spidermonkey/config.mk +192 -0
- data/vendor/spidermonkey/config/AIX4.1.mk +65 -0
- data/vendor/spidermonkey/config/AIX4.2.mk +64 -0
- data/vendor/spidermonkey/config/AIX4.3.mk +65 -0
- data/vendor/spidermonkey/config/Darwin.mk +83 -0
- data/vendor/spidermonkey/config/Darwin1.3.mk +81 -0
- data/vendor/spidermonkey/config/Darwin1.4.mk +41 -0
- data/vendor/spidermonkey/config/Darwin5.2.mk +81 -0
- data/vendor/spidermonkey/config/Darwin5.3.mk +81 -0
- data/vendor/spidermonkey/config/HP-UXB.10.10.mk +77 -0
- data/vendor/spidermonkey/config/HP-UXB.10.20.mk +77 -0
- data/vendor/spidermonkey/config/HP-UXB.11.00.mk +80 -0
- data/vendor/spidermonkey/config/IRIX.mk +87 -0
- data/vendor/spidermonkey/config/IRIX5.3.mk +44 -0
- data/vendor/spidermonkey/config/IRIX6.1.mk +44 -0
- data/vendor/spidermonkey/config/IRIX6.2.mk +44 -0
- data/vendor/spidermonkey/config/IRIX6.3.mk +44 -0
- data/vendor/spidermonkey/config/IRIX6.5.mk +44 -0
- data/vendor/spidermonkey/config/Linux_All.mk +103 -0
- data/vendor/spidermonkey/config/Mac_OS10.0.mk +82 -0
- data/vendor/spidermonkey/config/OSF1V4.0.mk +72 -0
- data/vendor/spidermonkey/config/OSF1V5.0.mk +69 -0
- data/vendor/spidermonkey/config/SunOS4.1.4.mk +101 -0
- data/vendor/spidermonkey/config/SunOS5.10.mk +50 -0
- data/vendor/spidermonkey/config/SunOS5.3.mk +91 -0
- data/vendor/spidermonkey/config/SunOS5.4.mk +92 -0
- data/vendor/spidermonkey/config/SunOS5.5.1.mk +44 -0
- data/vendor/spidermonkey/config/SunOS5.5.mk +87 -0
- data/vendor/spidermonkey/config/SunOS5.6.mk +89 -0
- data/vendor/spidermonkey/config/SunOS5.7.mk +44 -0
- data/vendor/spidermonkey/config/SunOS5.8.mk +44 -0
- data/vendor/spidermonkey/config/SunOS5.9.mk +44 -0
- data/vendor/spidermonkey/config/WINNT4.0.mk +117 -0
- data/vendor/spidermonkey/config/WINNT5.0.mk +117 -0
- data/vendor/spidermonkey/config/WINNT5.1.mk +117 -0
- data/vendor/spidermonkey/config/WINNT5.2.mk +117 -0
- data/vendor/spidermonkey/config/WINNT6.0.mk +117 -0
- data/vendor/spidermonkey/config/dgux.mk +64 -0
- data/vendor/spidermonkey/editline/Makefile.ref +144 -0
- data/vendor/spidermonkey/editline/README +83 -0
- data/vendor/spidermonkey/editline/editline.3 +175 -0
- data/vendor/spidermonkey/editline/editline.c +1369 -0
- data/vendor/spidermonkey/editline/editline.h +135 -0
- data/vendor/spidermonkey/editline/sysunix.c +182 -0
- data/vendor/spidermonkey/editline/unix.h +82 -0
- data/vendor/spidermonkey/fdlibm/.cvsignore +7 -0
- data/vendor/spidermonkey/fdlibm/Makefile.in +127 -0
- data/vendor/spidermonkey/fdlibm/Makefile.ref +192 -0
- data/vendor/spidermonkey/fdlibm/e_acos.c +147 -0
- data/vendor/spidermonkey/fdlibm/e_acosh.c +105 -0
- data/vendor/spidermonkey/fdlibm/e_asin.c +156 -0
- data/vendor/spidermonkey/fdlibm/e_atan2.c +165 -0
- data/vendor/spidermonkey/fdlibm/e_atanh.c +110 -0
- data/vendor/spidermonkey/fdlibm/e_cosh.c +133 -0
- data/vendor/spidermonkey/fdlibm/e_exp.c +202 -0
- data/vendor/spidermonkey/fdlibm/e_fmod.c +184 -0
- data/vendor/spidermonkey/fdlibm/e_gamma.c +71 -0
- data/vendor/spidermonkey/fdlibm/e_gamma_r.c +70 -0
- data/vendor/spidermonkey/fdlibm/e_hypot.c +173 -0
- data/vendor/spidermonkey/fdlibm/e_j0.c +524 -0
- data/vendor/spidermonkey/fdlibm/e_j1.c +523 -0
- data/vendor/spidermonkey/fdlibm/e_jn.c +315 -0
- data/vendor/spidermonkey/fdlibm/e_lgamma.c +71 -0
- data/vendor/spidermonkey/fdlibm/e_lgamma_r.c +347 -0
- data/vendor/spidermonkey/fdlibm/e_log.c +184 -0
- data/vendor/spidermonkey/fdlibm/e_log10.c +134 -0
- data/vendor/spidermonkey/fdlibm/e_pow.c +386 -0
- data/vendor/spidermonkey/fdlibm/e_rem_pio2.c +222 -0
- data/vendor/spidermonkey/fdlibm/e_remainder.c +120 -0
- data/vendor/spidermonkey/fdlibm/e_scalb.c +89 -0
- data/vendor/spidermonkey/fdlibm/e_sinh.c +122 -0
- data/vendor/spidermonkey/fdlibm/e_sqrt.c +497 -0
- data/vendor/spidermonkey/fdlibm/fdlibm.h +273 -0
- data/vendor/spidermonkey/fdlibm/fdlibm.mak +1453 -0
- data/vendor/spidermonkey/fdlibm/fdlibm.mdp +0 -0
- data/vendor/spidermonkey/fdlibm/k_cos.c +135 -0
- data/vendor/spidermonkey/fdlibm/k_rem_pio2.c +354 -0
- data/vendor/spidermonkey/fdlibm/k_sin.c +114 -0
- data/vendor/spidermonkey/fdlibm/k_standard.c +785 -0
- data/vendor/spidermonkey/fdlibm/k_tan.c +170 -0
- data/vendor/spidermonkey/fdlibm/s_asinh.c +101 -0
- data/vendor/spidermonkey/fdlibm/s_atan.c +175 -0
- data/vendor/spidermonkey/fdlibm/s_cbrt.c +133 -0
- data/vendor/spidermonkey/fdlibm/s_ceil.c +120 -0
- data/vendor/spidermonkey/fdlibm/s_copysign.c +72 -0
- data/vendor/spidermonkey/fdlibm/s_cos.c +118 -0
- data/vendor/spidermonkey/fdlibm/s_erf.c +356 -0
- data/vendor/spidermonkey/fdlibm/s_expm1.c +267 -0
- data/vendor/spidermonkey/fdlibm/s_fabs.c +70 -0
- data/vendor/spidermonkey/fdlibm/s_finite.c +71 -0
- data/vendor/spidermonkey/fdlibm/s_floor.c +121 -0
- data/vendor/spidermonkey/fdlibm/s_frexp.c +99 -0
- data/vendor/spidermonkey/fdlibm/s_ilogb.c +85 -0
- data/vendor/spidermonkey/fdlibm/s_isnan.c +74 -0
- data/vendor/spidermonkey/fdlibm/s_ldexp.c +66 -0
- data/vendor/spidermonkey/fdlibm/s_lib_version.c +73 -0
- data/vendor/spidermonkey/fdlibm/s_log1p.c +211 -0
- data/vendor/spidermonkey/fdlibm/s_logb.c +79 -0
- data/vendor/spidermonkey/fdlibm/s_matherr.c +64 -0
- data/vendor/spidermonkey/fdlibm/s_modf.c +132 -0
- data/vendor/spidermonkey/fdlibm/s_nextafter.c +124 -0
- data/vendor/spidermonkey/fdlibm/s_rint.c +131 -0
- data/vendor/spidermonkey/fdlibm/s_scalbn.c +107 -0
- data/vendor/spidermonkey/fdlibm/s_signgam.c +40 -0
- data/vendor/spidermonkey/fdlibm/s_significand.c +68 -0
- data/vendor/spidermonkey/fdlibm/s_sin.c +118 -0
- data/vendor/spidermonkey/fdlibm/s_tan.c +112 -0
- data/vendor/spidermonkey/fdlibm/s_tanh.c +122 -0
- data/vendor/spidermonkey/fdlibm/w_acos.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_acosh.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_asin.c +80 -0
- data/vendor/spidermonkey/fdlibm/w_atan2.c +79 -0
- data/vendor/spidermonkey/fdlibm/w_atanh.c +81 -0
- data/vendor/spidermonkey/fdlibm/w_cosh.c +77 -0
- data/vendor/spidermonkey/fdlibm/w_exp.c +88 -0
- data/vendor/spidermonkey/fdlibm/w_fmod.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_gamma.c +85 -0
- data/vendor/spidermonkey/fdlibm/w_gamma_r.c +81 -0
- data/vendor/spidermonkey/fdlibm/w_hypot.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_j0.c +105 -0
- data/vendor/spidermonkey/fdlibm/w_j1.c +106 -0
- data/vendor/spidermonkey/fdlibm/w_jn.c +128 -0
- data/vendor/spidermonkey/fdlibm/w_lgamma.c +85 -0
- data/vendor/spidermonkey/fdlibm/w_lgamma_r.c +81 -0
- data/vendor/spidermonkey/fdlibm/w_log.c +78 -0
- data/vendor/spidermonkey/fdlibm/w_log10.c +81 -0
- data/vendor/spidermonkey/fdlibm/w_pow.c +99 -0
- data/vendor/spidermonkey/fdlibm/w_remainder.c +77 -0
- data/vendor/spidermonkey/fdlibm/w_scalb.c +95 -0
- data/vendor/spidermonkey/fdlibm/w_sinh.c +77 -0
- data/vendor/spidermonkey/fdlibm/w_sqrt.c +77 -0
- data/vendor/spidermonkey/javascript-trace.d +73 -0
- data/vendor/spidermonkey/js.c +3951 -0
- data/vendor/spidermonkey/js.mdp +0 -0
- data/vendor/spidermonkey/js.msg +308 -0
- data/vendor/spidermonkey/js3240.rc +79 -0
- data/vendor/spidermonkey/jsOS240.def +654 -0
- data/vendor/spidermonkey/jsapi.c +5836 -0
- data/vendor/spidermonkey/jsapi.h +2624 -0
- data/vendor/spidermonkey/jsarena.c +450 -0
- data/vendor/spidermonkey/jsarena.h +318 -0
- data/vendor/spidermonkey/jsarray.c +2996 -0
- data/vendor/spidermonkey/jsarray.h +127 -0
- data/vendor/spidermonkey/jsatom.c +1045 -0
- data/vendor/spidermonkey/jsatom.h +442 -0
- data/vendor/spidermonkey/jsbit.h +253 -0
- data/vendor/spidermonkey/jsbool.c +176 -0
- data/vendor/spidermonkey/jsbool.h +73 -0
- data/vendor/spidermonkey/jsclist.h +139 -0
- data/vendor/spidermonkey/jscntxt.c +1348 -0
- data/vendor/spidermonkey/jscntxt.h +1120 -0
- data/vendor/spidermonkey/jscompat.h +57 -0
- data/vendor/spidermonkey/jsconfig.h +248 -0
- data/vendor/spidermonkey/jsconfig.mk +181 -0
- data/vendor/spidermonkey/jscpucfg.c +396 -0
- data/vendor/spidermonkey/jscpucfg.h +212 -0
- data/vendor/spidermonkey/jsdate.c +2390 -0
- data/vendor/spidermonkey/jsdate.h +124 -0
- data/vendor/spidermonkey/jsdbgapi.c +1802 -0
- data/vendor/spidermonkey/jsdbgapi.h +464 -0
- data/vendor/spidermonkey/jsdhash.c +868 -0
- data/vendor/spidermonkey/jsdhash.h +592 -0
- data/vendor/spidermonkey/jsdtoa.c +3167 -0
- data/vendor/spidermonkey/jsdtoa.h +130 -0
- data/vendor/spidermonkey/jsdtracef.c +317 -0
- data/vendor/spidermonkey/jsdtracef.h +77 -0
- data/vendor/spidermonkey/jsemit.c +6909 -0
- data/vendor/spidermonkey/jsemit.h +741 -0
- data/vendor/spidermonkey/jsexn.c +1371 -0
- data/vendor/spidermonkey/jsexn.h +96 -0
- data/vendor/spidermonkey/jsfile.c +2736 -0
- data/vendor/spidermonkey/jsfile.h +56 -0
- data/vendor/spidermonkey/jsfile.msg +90 -0
- data/vendor/spidermonkey/jsfun.c +2634 -0
- data/vendor/spidermonkey/jsfun.h +254 -0
- data/vendor/spidermonkey/jsgc.c +3562 -0
- data/vendor/spidermonkey/jsgc.h +403 -0
- data/vendor/spidermonkey/jshash.c +476 -0
- data/vendor/spidermonkey/jshash.h +151 -0
- data/vendor/spidermonkey/jsify.pl +485 -0
- data/vendor/spidermonkey/jsinterp.c +7007 -0
- data/vendor/spidermonkey/jsinterp.h +525 -0
- data/vendor/spidermonkey/jsinvoke.c +43 -0
- data/vendor/spidermonkey/jsiter.c +1067 -0
- data/vendor/spidermonkey/jsiter.h +122 -0
- data/vendor/spidermonkey/jskeyword.tbl +124 -0
- data/vendor/spidermonkey/jskwgen.c +460 -0
- data/vendor/spidermonkey/jslibmath.h +266 -0
- data/vendor/spidermonkey/jslock.c +1309 -0
- data/vendor/spidermonkey/jslock.h +313 -0
- data/vendor/spidermonkey/jslocko.asm +60 -0
- data/vendor/spidermonkey/jslog2.c +94 -0
- data/vendor/spidermonkey/jslong.c +264 -0
- data/vendor/spidermonkey/jslong.h +412 -0
- data/vendor/spidermonkey/jsmath.c +567 -0
- data/vendor/spidermonkey/jsmath.h +57 -0
- data/vendor/spidermonkey/jsnum.c +1239 -0
- data/vendor/spidermonkey/jsnum.h +283 -0
- data/vendor/spidermonkey/jsobj.c +5282 -0
- data/vendor/spidermonkey/jsobj.h +709 -0
- data/vendor/spidermonkey/jsopcode.c +5245 -0
- data/vendor/spidermonkey/jsopcode.h +394 -0
- data/vendor/spidermonkey/jsopcode.tbl +523 -0
- data/vendor/spidermonkey/jsotypes.h +202 -0
- data/vendor/spidermonkey/jsparse.c +6704 -0
- data/vendor/spidermonkey/jsparse.h +511 -0
- data/vendor/spidermonkey/jsprf.c +1262 -0
- data/vendor/spidermonkey/jsprf.h +150 -0
- data/vendor/spidermonkey/jsproto.tbl +128 -0
- data/vendor/spidermonkey/jsprvtd.h +267 -0
- data/vendor/spidermonkey/jspubtd.h +744 -0
- data/vendor/spidermonkey/jsregexp.c +4364 -0
- data/vendor/spidermonkey/jsregexp.h +183 -0
- data/vendor/spidermonkey/jsreops.tbl +145 -0
- data/vendor/spidermonkey/jsscan.c +2012 -0
- data/vendor/spidermonkey/jsscan.h +387 -0
- data/vendor/spidermonkey/jsscope.c +1957 -0
- data/vendor/spidermonkey/jsscope.h +418 -0
- data/vendor/spidermonkey/jsscript.c +1832 -0
- data/vendor/spidermonkey/jsscript.h +287 -0
- data/vendor/spidermonkey/jsshell.msg +50 -0
- data/vendor/spidermonkey/jsstddef.h +83 -0
- data/vendor/spidermonkey/jsstr.c +5005 -0
- data/vendor/spidermonkey/jsstr.h +641 -0
- data/vendor/spidermonkey/jstypes.h +475 -0
- data/vendor/spidermonkey/jsutil.c +345 -0
- data/vendor/spidermonkey/jsutil.h +157 -0
- data/vendor/spidermonkey/jsxdrapi.c +800 -0
- data/vendor/spidermonkey/jsxdrapi.h +218 -0
- data/vendor/spidermonkey/jsxml.c +8476 -0
- data/vendor/spidermonkey/jsxml.h +349 -0
- data/vendor/spidermonkey/lock_SunOS.s +119 -0
- data/vendor/spidermonkey/perfect.js +39 -0
- data/vendor/spidermonkey/plify_jsdhash.sed +36 -0
- data/vendor/spidermonkey/prmjtime.c +846 -0
- data/vendor/spidermonkey/prmjtime.h +103 -0
- data/vendor/spidermonkey/resource.h +15 -0
- data/vendor/spidermonkey/rules.mk +197 -0
- data/vendor/spidermonkey/win32.order +384 -0
- metadata +513 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
#ifndef JOHNSON_SPIDERMONKEY_IMMUTABLE_NODE_H
|
2
|
+
#define JOHNSON_SPIDERMONKEY_IMMUTABLE_NODE_H
|
3
|
+
|
4
|
+
#include "spidermonkey.h"
|
5
|
+
#include "jsparse.h"
|
6
|
+
#include "jsatom.h"
|
7
|
+
#include "jsscan.h"
|
8
|
+
#include "jsarena.h"
|
9
|
+
#include "jsfun.h"
|
10
|
+
#include "jscntxt.h"
|
11
|
+
|
12
|
+
typedef struct {
|
13
|
+
JSParseContext * pc;
|
14
|
+
JSParseNode * node;
|
15
|
+
JSContext * js;
|
16
|
+
JSRuntime * runtime;
|
17
|
+
} ImmutableNodeContext;
|
18
|
+
|
19
|
+
VALUE jsop_to_symbol(JSUint32 jsop);
|
20
|
+
void init_Johnson_SpiderMonkey_Immutable_Node(VALUE spidermonkey);
|
21
|
+
|
22
|
+
#endif
|
@@ -0,0 +1,187 @@
|
|
1
|
+
#ifndef JOHNSON_JROOT_H
|
2
|
+
#define JOHNSON_JROOT_H
|
3
|
+
|
4
|
+
#define _JROOT_NAMESIZE 200L
|
5
|
+
#define _JROOT_ERRSIZE 500L
|
6
|
+
|
7
|
+
#define _JROOT_ROOT (void*)(1)
|
8
|
+
|
9
|
+
#define OUR_CONTEXT(js_context) \
|
10
|
+
({ \
|
11
|
+
JohnsonContext* _context; \
|
12
|
+
const VALUE _ruby_context = (VALUE)JS_GetContextPrivate(js_context); \
|
13
|
+
Data_Get_Struct(_ruby_context, JohnsonContext, _context); \
|
14
|
+
_context; \
|
15
|
+
})
|
16
|
+
|
17
|
+
#define OUR_RUNTIME(js_context) \
|
18
|
+
({ \
|
19
|
+
JohnsonRuntime* _johnson_runtime; \
|
20
|
+
JSRuntime * _js_runtime = JS_GetRuntime(js_context);\
|
21
|
+
const VALUE _ruby_runtime = (VALUE)JS_GetRuntimePrivate(_js_runtime); \
|
22
|
+
Data_Get_Struct(_ruby_runtime, JohnsonRuntime, _johnson_runtime); \
|
23
|
+
_johnson_runtime; \
|
24
|
+
})
|
25
|
+
|
26
|
+
|
27
|
+
#define _PREPARE_JROOTS(rb, context, cleancount) \
|
28
|
+
const bool _jroot_ruby = (rb); \
|
29
|
+
const int _jroot_cleans = (cleancount); \
|
30
|
+
void (*_jroot_cleanup[_jroot_cleans])(JSContext*, void*); \
|
31
|
+
void* _jroot_cleanup_data[_jroot_cleans]; \
|
32
|
+
JSContext* const _jroot_context = (context); \
|
33
|
+
int _jroot_cleanidx = 0;
|
34
|
+
|
35
|
+
#define PREPARE_JROOTS(context, cleancount) \
|
36
|
+
_PREPARE_JROOTS(false, context, cleancount)
|
37
|
+
|
38
|
+
#define PREPARE_RUBY_JROOTS(context, cleancount) \
|
39
|
+
_PREPARE_JROOTS(true, context, cleancount)
|
40
|
+
|
41
|
+
#define JCLEANUP(func, data) \
|
42
|
+
do \
|
43
|
+
{ \
|
44
|
+
assert(_jroot_cleanidx < _jroot_cleans); \
|
45
|
+
_jroot_cleanup[_jroot_cleanidx] = (func); \
|
46
|
+
_jroot_cleanup_data[_jroot_cleanidx] = (data); \
|
47
|
+
_jroot_cleanidx++; \
|
48
|
+
} while(0)
|
49
|
+
|
50
|
+
#define _JROOT(ptr, name) \
|
51
|
+
do \
|
52
|
+
{ \
|
53
|
+
static char _name[_JROOT_NAMESIZE] = ""; \
|
54
|
+
void* const _root = (ptr); \
|
55
|
+
if (*_name == '\0') \
|
56
|
+
snprintf(_name, _JROOT_NAMESIZE, "%s[%d]:%s: %s", __FILE__, __LINE__, __func__, (name)); \
|
57
|
+
JCHECK(JS_AddNamedRoot(_jroot_context, _root, _name)); \
|
58
|
+
JCLEANUP(_JROOT_ROOT, _root); \
|
59
|
+
} while(0)
|
60
|
+
|
61
|
+
#define JROOT(var) _JROOT(&(var), #var)
|
62
|
+
#define JROOT_PTR(ptr) _JROOT(ptr, #ptr)
|
63
|
+
|
64
|
+
#define JUNROOT(var) \
|
65
|
+
do \
|
66
|
+
{ \
|
67
|
+
void* const _jroot_match = &(var); \
|
68
|
+
int _jroot_i; \
|
69
|
+
for (_jroot_i = _jroot_cleanidx - 1; _jroot_i >= 0; _jroot_i--) \
|
70
|
+
if (_jroot_cleanup[_jroot_i] == _JROOT_ROOT && _jroot_cleanup_data[_jroot_i] == _jroot_match) \
|
71
|
+
{ \
|
72
|
+
JS_RemoveRoot(_jroot_context, _jroot_cleanup_data[_jroot_i]); \
|
73
|
+
if (_jroot_i == _jroot_cleanidx - 1) _jroot_cleanidx--; \
|
74
|
+
_jroot_cleanup[_jroot_i] = NULL; \
|
75
|
+
} \
|
76
|
+
} while (0)
|
77
|
+
|
78
|
+
#define REMOVE_JROOTS \
|
79
|
+
do \
|
80
|
+
{ \
|
81
|
+
int _jroot_i; \
|
82
|
+
for (_jroot_i = _jroot_cleanidx - 1; _jroot_i >= 0; _jroot_i--) \
|
83
|
+
{ \
|
84
|
+
if (_jroot_cleanup[_jroot_i] == _JROOT_ROOT) \
|
85
|
+
JS_RemoveRoot(_jroot_context, _jroot_cleanup_data[_jroot_i]); \
|
86
|
+
else if (_jroot_cleanup[_jroot_i]) \
|
87
|
+
(_jroot_cleanup[_jroot_i])(_jroot_context, _jroot_cleanup_data[_jroot_i]); \
|
88
|
+
} \
|
89
|
+
} while (0)
|
90
|
+
|
91
|
+
#define JCHECK_RUBY(cond) \
|
92
|
+
do \
|
93
|
+
{ \
|
94
|
+
assert(_jroot_ruby); \
|
95
|
+
if (!(cond)) \
|
96
|
+
{ \
|
97
|
+
REMOVE_JROOTS; \
|
98
|
+
raise_js_error_in_ruby(OUR_RUNTIME(_jroot_context)); \
|
99
|
+
} \
|
100
|
+
} while (0)
|
101
|
+
|
102
|
+
#define JCHECK(cond) \
|
103
|
+
do \
|
104
|
+
{ \
|
105
|
+
if (!(cond)) \
|
106
|
+
{ \
|
107
|
+
REMOVE_JROOTS; \
|
108
|
+
if (_jroot_ruby) \
|
109
|
+
raise_js_error_in_ruby(OUR_RUNTIME(_jroot_context)); \
|
110
|
+
else \
|
111
|
+
return JS_FALSE; \
|
112
|
+
} \
|
113
|
+
} while (0)
|
114
|
+
|
115
|
+
#define JPROTECT(func, data) \
|
116
|
+
({ \
|
117
|
+
int _state; \
|
118
|
+
const VALUE _old_errinfo = ruby_errinfo; \
|
119
|
+
const VALUE _result = rb_protect((func), (data), &_state); \
|
120
|
+
if (_state) \
|
121
|
+
{ \
|
122
|
+
REMOVE_JROOTS; \
|
123
|
+
if (_jroot_ruby) \
|
124
|
+
rb_jump_tag(_state); \
|
125
|
+
else \
|
126
|
+
return report_ruby_error_in_js(OUR_RUNTIME(_jroot_context), _state, _old_errinfo); \
|
127
|
+
} \
|
128
|
+
_result; \
|
129
|
+
})
|
130
|
+
|
131
|
+
#define JRETURN \
|
132
|
+
do \
|
133
|
+
{ \
|
134
|
+
assert(!_jroot_ruby); \
|
135
|
+
REMOVE_JROOTS; \
|
136
|
+
return JS_TRUE; \
|
137
|
+
} while(0)
|
138
|
+
|
139
|
+
#define JRETURN_RUBY(value) \
|
140
|
+
do \
|
141
|
+
{ \
|
142
|
+
assert(_jroot_ruby); \
|
143
|
+
typeof(value) _jroot_result = (value); \
|
144
|
+
REMOVE_JROOTS; \
|
145
|
+
return _jroot_result; \
|
146
|
+
} while(0)
|
147
|
+
|
148
|
+
#define JERROR(format, args...) \
|
149
|
+
do \
|
150
|
+
{ \
|
151
|
+
REMOVE_JROOTS; \
|
152
|
+
char _jroot_msg[_JROOT_ERRSIZE]; \
|
153
|
+
snprintf(_jroot_msg, _JROOT_ERRSIZE, (format) , ## args); \
|
154
|
+
if (_jroot_ruby) \
|
155
|
+
rb_raise(rb_eRuntimeError, _jroot_msg); \
|
156
|
+
else \
|
157
|
+
{ \
|
158
|
+
JSString* _jroot_err_str = JS_NewStringCopyZ(_jroot_context, _jroot_msg); \
|
159
|
+
if (_jroot_err_str) JS_SetPendingException(_jroot_context, STRING_TO_JSVAL(_jroot_err_str)); \
|
160
|
+
return JS_FALSE; \
|
161
|
+
} \
|
162
|
+
} while(0)
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
#define ARGLIST1(a) _data->a
|
168
|
+
#define ARGLIST2(a, b) _data->a, _data->b
|
169
|
+
#define ARGLIST3(a, b, c) _data->a, _data->b, _data->c
|
170
|
+
#define ARGLIST4(a, b, c, d) _data->a, _data->b, _data->c, _data->d
|
171
|
+
#define ARGLIST5(a, b, c, d, e) _data->a, _data->b, _data->c, _data->d, _data->e
|
172
|
+
|
173
|
+
#define DECLARE_RUBY_WRAPPER(name, args) \
|
174
|
+
typedef struct { args; } name ## _args; \
|
175
|
+
VALUE name ## _invoke(VALUE magic);
|
176
|
+
#define DEFINE_RUBY_WRAPPER(name, func, arglist) \
|
177
|
+
VALUE name ## _invoke(VALUE magic) \
|
178
|
+
{ \
|
179
|
+
name ## _args * _data = (name ## _args *)(FIX2LONG(magic) << 2); \
|
180
|
+
return func(arglist); \
|
181
|
+
}
|
182
|
+
#define RUBY_WRAPPER_ARG(name, args...) ({ name ## _args _x = { args }; LONG2FIX((long)(&_x) >> 2); })
|
183
|
+
#define RUBY_WRAPPER(name) name ## _invoke
|
184
|
+
#define CALL_RUBY_WRAPPER(name, args...) JPROTECT(RUBY_WRAPPER(name), RUBY_WRAPPER_ARG(name, args))
|
185
|
+
|
186
|
+
|
187
|
+
#endif
|
@@ -0,0 +1,610 @@
|
|
1
|
+
#include "js_land_proxy.h"
|
2
|
+
#include "conversions.h"
|
3
|
+
|
4
|
+
static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval);
|
5
|
+
static JSBool set(JSContext* context, JSObject* obj, jsval id, jsval* retval);
|
6
|
+
static JSBool construct(JSContext* js_context, JSObject* obj, uintN argc, jsval* argv, jsval* retval);
|
7
|
+
static JSBool resolve(JSContext *js_context, JSObject *obj, jsval id, uintN flags, JSObject **objp);
|
8
|
+
static JSBool call(JSContext* js_context, JSObject* obj, uintN argc, jsval* argv, jsval* retval);
|
9
|
+
static void finalize(JSContext* context, JSObject* obj);
|
10
|
+
|
11
|
+
static JSClass JSLandProxyClass = {
|
12
|
+
"JSLandProxy", JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE,
|
13
|
+
JS_PropertyStub,
|
14
|
+
JS_PropertyStub,
|
15
|
+
get,
|
16
|
+
set,
|
17
|
+
JS_EnumerateStub,
|
18
|
+
(JSResolveOp) resolve,
|
19
|
+
JS_ConvertStub,
|
20
|
+
finalize
|
21
|
+
};
|
22
|
+
|
23
|
+
static JSClass JSLandClassProxyClass = {
|
24
|
+
"JSLandClassProxy", JSCLASS_HAS_PRIVATE,
|
25
|
+
JS_PropertyStub,
|
26
|
+
JS_PropertyStub,
|
27
|
+
get,
|
28
|
+
set,
|
29
|
+
JS_EnumerateStub,
|
30
|
+
JS_ResolveStub,
|
31
|
+
JS_ConvertStub,
|
32
|
+
finalize,
|
33
|
+
NULL,
|
34
|
+
NULL,
|
35
|
+
NULL,
|
36
|
+
construct
|
37
|
+
};
|
38
|
+
|
39
|
+
static JSClass JSLandCallableProxyClass = {
|
40
|
+
"JSLandCallableProxy", JSCLASS_HAS_PRIVATE,
|
41
|
+
JS_PropertyStub,
|
42
|
+
JS_PropertyStub,
|
43
|
+
get,
|
44
|
+
set,
|
45
|
+
JS_EnumerateStub,
|
46
|
+
JS_ResolveStub,
|
47
|
+
JS_ConvertStub,
|
48
|
+
finalize,
|
49
|
+
NULL,
|
50
|
+
NULL,
|
51
|
+
call
|
52
|
+
};
|
53
|
+
|
54
|
+
static VALUE call_ruby_from_js_invoke(VALUE args)
|
55
|
+
{
|
56
|
+
VALUE self = rb_ary_pop(args);
|
57
|
+
VALUE id = rb_ary_pop(args);
|
58
|
+
return rb_apply(self, SYM2ID(id), args);
|
59
|
+
}
|
60
|
+
|
61
|
+
JSBool call_ruby_from_js_va(JohnsonRuntime* runtime, VALUE* result, VALUE self, ID id, int argc, va_list va)
|
62
|
+
{
|
63
|
+
VALUE old_errinfo = ruby_errinfo;
|
64
|
+
VALUE args = rb_ary_new2((long)argc + 2);
|
65
|
+
|
66
|
+
long i;
|
67
|
+
for(i = 0; i < argc; i++)
|
68
|
+
rb_ary_store(args, i, va_arg(va, VALUE));
|
69
|
+
|
70
|
+
rb_ary_store(args, (long)argc, ID2SYM(id));
|
71
|
+
rb_ary_store(args, (long)argc + 1, self);
|
72
|
+
|
73
|
+
int state;
|
74
|
+
*result = rb_protect(call_ruby_from_js_invoke, args, &state);
|
75
|
+
|
76
|
+
if (state)
|
77
|
+
return report_ruby_error_in_js(runtime, state, old_errinfo);
|
78
|
+
|
79
|
+
return JS_TRUE;
|
80
|
+
}
|
81
|
+
|
82
|
+
JSBool call_ruby_from_js(JohnsonRuntime* runtime, jsval* retval, VALUE self, ID id, int argc, ...)
|
83
|
+
{
|
84
|
+
VALUE result;
|
85
|
+
va_list va;
|
86
|
+
va_start(va, argc);
|
87
|
+
JSBool okay = call_ruby_from_js_va(runtime, &result, self, id, argc, va);
|
88
|
+
va_end(va);
|
89
|
+
if (!okay) return JS_FALSE;
|
90
|
+
return retval ? convert_to_js(runtime, result, retval) : JS_TRUE;
|
91
|
+
}
|
92
|
+
|
93
|
+
JSBool call_ruby_from_js2(JohnsonRuntime* runtime, VALUE* retval, VALUE self, ID id, int argc, ...)
|
94
|
+
{
|
95
|
+
va_list va;
|
96
|
+
va_start(va, argc);
|
97
|
+
JSBool okay = call_ruby_from_js_va(runtime, retval, self, id, argc, va);
|
98
|
+
va_end(va);
|
99
|
+
return okay;
|
100
|
+
}
|
101
|
+
|
102
|
+
static bool autovivified_p(VALUE UNUSED(ruby_context), VALUE self, char* name)
|
103
|
+
{
|
104
|
+
return RTEST(rb_funcall(Johnson_SpiderMonkey_JSLandProxy(), rb_intern("autovivified?"), 2,
|
105
|
+
self, rb_str_new2(name)));
|
106
|
+
}
|
107
|
+
|
108
|
+
static bool const_p(VALUE self, char* name)
|
109
|
+
{
|
110
|
+
return rb_obj_is_kind_of(self, rb_cModule)
|
111
|
+
&& rb_is_const_id(rb_intern(name))
|
112
|
+
&& RTEST( rb_funcall(self, rb_intern("const_defined?"), 1, ID2SYM(rb_intern(name))) );
|
113
|
+
}
|
114
|
+
|
115
|
+
static bool global_p(char* name)
|
116
|
+
{
|
117
|
+
return *name == '$' && rb_ary_includes(rb_f_global_variables(), rb_str_new2(name));
|
118
|
+
}
|
119
|
+
|
120
|
+
static bool method_p(VALUE self, char* name)
|
121
|
+
{
|
122
|
+
return RTEST( rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern(name))) );
|
123
|
+
}
|
124
|
+
|
125
|
+
static bool attribute_p(VALUE self, char* name)
|
126
|
+
{
|
127
|
+
if (!method_p(self, name))
|
128
|
+
return false;
|
129
|
+
|
130
|
+
VALUE rb_id = rb_intern(name);
|
131
|
+
VALUE rb_method = rb_funcall(self, rb_intern("method"), 1, ID2SYM(rb_id));
|
132
|
+
|
133
|
+
if (TYPE(rb_method) == T_DATA)
|
134
|
+
{
|
135
|
+
VALUE klass = CLASS_OF(rb_method);
|
136
|
+
if (klass == rb_cMethod)
|
137
|
+
{
|
138
|
+
METHOD* method;
|
139
|
+
Data_Get_Struct(rb_method, METHOD, method);
|
140
|
+
|
141
|
+
if (method && nd_type(method->body) == NODE_IVAR)
|
142
|
+
return true;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
return RTEST(rb_funcall(Johnson_SpiderMonkey_JSLandProxy(),
|
147
|
+
rb_intern("js_property?"), 2, self, ID2SYM(rb_id)));
|
148
|
+
}
|
149
|
+
|
150
|
+
static bool indexable_p(VALUE self)
|
151
|
+
{
|
152
|
+
return RTEST(rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("[]"))));
|
153
|
+
}
|
154
|
+
|
155
|
+
static bool has_key_p(VALUE self, char* name)
|
156
|
+
{
|
157
|
+
return RTEST(rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("[]"))))
|
158
|
+
&& RTEST(rb_funcall(self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("key?"))))
|
159
|
+
&& RTEST(rb_funcall(self, rb_intern("key?"), 1, rb_str_new2(name)));
|
160
|
+
}
|
161
|
+
|
162
|
+
static bool respond_to_p(JSContext* js_context, JSObject* obj, char* name)
|
163
|
+
{
|
164
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
165
|
+
|
166
|
+
JohnsonContext* context;
|
167
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
168
|
+
|
169
|
+
VALUE self = (VALUE)JS_GetInstancePrivate(
|
170
|
+
context->js, obj, JS_GET_CLASS(context->js, obj), NULL);
|
171
|
+
|
172
|
+
if (!self) return false;
|
173
|
+
|
174
|
+
return autovivified_p(ruby_context, self, name)
|
175
|
+
|| const_p(self, name)
|
176
|
+
|| global_p(name)
|
177
|
+
|| attribute_p(self, name)
|
178
|
+
|| method_p(self, name)
|
179
|
+
|| has_key_p(self, name);
|
180
|
+
}
|
181
|
+
|
182
|
+
static jsval evaluate_js_property_expression(JohnsonRuntime * runtime, const char * property, jsval* retval) {
|
183
|
+
JSContext * context = johnson_get_current_context(runtime);
|
184
|
+
assert(strlen(property) < INT_MAX);
|
185
|
+
return JS_EvaluateScript(context, runtime->global,
|
186
|
+
property, (unsigned int)strlen(property), "johnson:evaluate_js_property_expression", 1,
|
187
|
+
retval);
|
188
|
+
}
|
189
|
+
|
190
|
+
static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
|
191
|
+
{
|
192
|
+
// pull out our Ruby context, which is embedded in js_context
|
193
|
+
|
194
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
195
|
+
|
196
|
+
// get our struct, which is embedded in ruby_context
|
197
|
+
|
198
|
+
JohnsonContext* context;
|
199
|
+
JohnsonRuntime* runtime;
|
200
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
201
|
+
|
202
|
+
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(JS_GetRuntime(js_context));
|
203
|
+
Data_Get_Struct(ruby_runtime, JohnsonRuntime, runtime);
|
204
|
+
|
205
|
+
PREPARE_JROOTS(js_context, 1);
|
206
|
+
JROOT(id);
|
207
|
+
|
208
|
+
// get the Ruby object that backs this proxy
|
209
|
+
|
210
|
+
VALUE self = (VALUE)JS_GetInstancePrivate(context->js, obj, JS_GET_CLASS(context->js, obj), NULL);
|
211
|
+
|
212
|
+
// Short-circuit for numeric indexes
|
213
|
+
|
214
|
+
if (JSVAL_IS_INT(id))
|
215
|
+
{
|
216
|
+
if (indexable_p(self)) {
|
217
|
+
VALUE idx = INT2FIX(JSVAL_TO_INT(id));
|
218
|
+
JCHECK(call_ruby_from_js(runtime, retval, self, rb_intern("[]"), 1, idx));
|
219
|
+
}
|
220
|
+
|
221
|
+
JRETURN;
|
222
|
+
}
|
223
|
+
|
224
|
+
char* name = JS_GetStringBytes(JSVAL_TO_STRING(id));
|
225
|
+
VALUE ruby_id = rb_intern(name);
|
226
|
+
|
227
|
+
// FIXME: we should probably just JS_DefineProperty this, and it shouldn't be enumerable
|
228
|
+
|
229
|
+
if (!strcasecmp("__iterator__", name)) {
|
230
|
+
JCHECK(evaluate_js_property_expression(runtime, "Johnson.Generator.create", retval));
|
231
|
+
}
|
232
|
+
|
233
|
+
// if the Ruby object has a dynamic js property with a key
|
234
|
+
// matching the property we're looking for, pull the value out of
|
235
|
+
// that map.
|
236
|
+
|
237
|
+
else if (autovivified_p(ruby_context, self, name))
|
238
|
+
{
|
239
|
+
JCHECK(call_ruby_from_js(runtime, retval, Johnson_SpiderMonkey_JSLandProxy(),
|
240
|
+
rb_intern("autovivified"), 2, self, rb_str_new2(name)));
|
241
|
+
}
|
242
|
+
|
243
|
+
// if the Ruby object is a Module or Class and has a matching
|
244
|
+
// const defined, return the converted result of const_get
|
245
|
+
|
246
|
+
else if (const_p(self, name))
|
247
|
+
{
|
248
|
+
JCHECK(call_ruby_from_js(runtime, retval, self, rb_intern("const_get"),
|
249
|
+
1, ID2SYM(ruby_id)));
|
250
|
+
}
|
251
|
+
|
252
|
+
// otherwise, if it's a global, return the global
|
253
|
+
else if (global_p(name))
|
254
|
+
{
|
255
|
+
JCHECK(convert_to_js(runtime, rb_gv_get(name), retval));
|
256
|
+
}
|
257
|
+
|
258
|
+
// otherwise, if the Ruby object has a an attribute method matching
|
259
|
+
// the property we're trying to get, call it and return the converted result
|
260
|
+
|
261
|
+
else if (attribute_p(self, name))
|
262
|
+
{
|
263
|
+
JCHECK(call_ruby_from_js(runtime, retval, self, ruby_id, 0));
|
264
|
+
}
|
265
|
+
|
266
|
+
// otherwise, if the Ruby object quacks sorta like a hash (it responds to
|
267
|
+
// "[]" and "key?"), index it by key and return the converted result
|
268
|
+
|
269
|
+
else if (has_key_p(self, name))
|
270
|
+
{
|
271
|
+
JCHECK(call_ruby_from_js(runtime, retval, self, rb_intern("[]"), 1, rb_str_new2(name)));
|
272
|
+
}
|
273
|
+
|
274
|
+
// otherwise, it's a method being accessed as a property, which means
|
275
|
+
// we need to return a lambda
|
276
|
+
|
277
|
+
// FIXME: this should really wrap the Method for 'name' in a JS class
|
278
|
+
// rather than generating a wrapper Proc
|
279
|
+
|
280
|
+
else if (method_p(self, name))
|
281
|
+
{
|
282
|
+
JCHECK(call_ruby_from_js(runtime, retval, self, rb_intern("method"), 1, rb_str_new2(name)));
|
283
|
+
}
|
284
|
+
|
285
|
+
// else it's undefined (JS_VOID) by default
|
286
|
+
JRETURN;
|
287
|
+
}
|
288
|
+
|
289
|
+
// called for lazily resolved properties, which should go away
|
290
|
+
static JSBool get_and_destroy_resolved_property(
|
291
|
+
JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
|
292
|
+
{
|
293
|
+
PREPARE_JROOTS(js_context, 1);
|
294
|
+
JROOT(id);
|
295
|
+
char* name = JS_GetStringBytes(JSVAL_TO_STRING(id));
|
296
|
+
JCHECK(JS_DeleteProperty(js_context, obj, name));
|
297
|
+
JCHECK(get(js_context, obj, id, retval));
|
298
|
+
JRETURN;
|
299
|
+
}
|
300
|
+
|
301
|
+
static JSBool set(JSContext* js_context, JSObject* obj, jsval id, jsval* value)
|
302
|
+
{
|
303
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
304
|
+
|
305
|
+
JohnsonContext* context;
|
306
|
+
JohnsonRuntime* runtime;
|
307
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
308
|
+
|
309
|
+
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(JS_GetRuntime(js_context));
|
310
|
+
Data_Get_Struct(ruby_runtime, JohnsonRuntime, runtime);
|
311
|
+
|
312
|
+
PREPARE_JROOTS(js_context, 2);
|
313
|
+
JROOT(id);
|
314
|
+
JROOT_PTR(value);
|
315
|
+
|
316
|
+
VALUE self = (VALUE)JS_GetInstancePrivate(context->js, obj, JS_GET_CLASS(context->js, obj), NULL);
|
317
|
+
|
318
|
+
// Short-circuit for numeric indexes
|
319
|
+
|
320
|
+
if (JSVAL_IS_INT(id))
|
321
|
+
{
|
322
|
+
if (indexable_p(self))
|
323
|
+
{
|
324
|
+
VALUE idx = INT2FIX(JSVAL_TO_INT(id));
|
325
|
+
VALUE val = CONVERT_TO_RUBY(runtime, *value);
|
326
|
+
|
327
|
+
JCHECK(call_ruby_from_js(runtime, NULL, self, rb_intern("[]="), 2, idx, val));
|
328
|
+
}
|
329
|
+
|
330
|
+
JRETURN;
|
331
|
+
}
|
332
|
+
|
333
|
+
VALUE ruby_key = CONVERT_TO_RUBY(runtime, id);
|
334
|
+
VALUE ruby_value = CONVERT_TO_RUBY(runtime, *value);
|
335
|
+
|
336
|
+
VALUE setter = rb_str_append(rb_str_new3(ruby_key), rb_str_new2("="));
|
337
|
+
VALUE setter_id = rb_intern(StringValueCStr(setter));
|
338
|
+
|
339
|
+
VALUE settable_p, indexable_p;
|
340
|
+
JCHECK(call_ruby_from_js2(runtime, &settable_p, self, rb_intern("respond_to?"), 1, ID2SYM(setter_id)));
|
341
|
+
JCHECK(call_ruby_from_js2(runtime, &indexable_p, self, rb_intern("respond_to?"), 1, ID2SYM(rb_intern("[]="))));
|
342
|
+
|
343
|
+
if (settable_p)
|
344
|
+
{
|
345
|
+
VALUE method, arity;
|
346
|
+
JCHECK(call_ruby_from_js2(runtime, &method, self, rb_intern("method"), 1, ID2SYM(setter_id)));
|
347
|
+
JCHECK(call_ruby_from_js2(runtime, &arity, method, rb_intern("arity"), 0));
|
348
|
+
|
349
|
+
// if the Ruby object has a 1-arity method named "property=",
|
350
|
+
// call it with the converted value
|
351
|
+
|
352
|
+
if (NUM2INT(arity) == 1)
|
353
|
+
JCHECK(call_ruby_from_js(runtime, NULL, self, setter_id, 1, ruby_value));
|
354
|
+
}
|
355
|
+
else if(indexable_p)
|
356
|
+
{
|
357
|
+
// otherwise, if the Ruby object quacks sorta like a hash for assignment
|
358
|
+
// (it responds to "[]="), assign it by key
|
359
|
+
|
360
|
+
JCHECK(call_ruby_from_js(runtime, NULL, self, rb_intern("[]="), 2, ruby_key, ruby_value));
|
361
|
+
}
|
362
|
+
else
|
363
|
+
{
|
364
|
+
JCHECK(call_ruby_from_js(runtime, NULL, Johnson_SpiderMonkey_JSLandProxy(), rb_intern("autovivify"),
|
365
|
+
3, self, ruby_key, ruby_value));
|
366
|
+
}
|
367
|
+
|
368
|
+
JRETURN;
|
369
|
+
}
|
370
|
+
|
371
|
+
static JSBool construct(JSContext* js_context, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* retval)
|
372
|
+
{
|
373
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
374
|
+
|
375
|
+
JohnsonContext* context;
|
376
|
+
JohnsonRuntime* runtime;
|
377
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
378
|
+
|
379
|
+
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(JS_GetRuntime(js_context));
|
380
|
+
Data_Get_Struct(ruby_runtime, JohnsonRuntime, runtime);
|
381
|
+
|
382
|
+
PREPARE_JROOTS(js_context, 0);
|
383
|
+
|
384
|
+
VALUE klass = CONVERT_TO_RUBY(runtime, JS_ARGV_CALLEE(argv));
|
385
|
+
VALUE args = rb_ary_new();
|
386
|
+
|
387
|
+
uintN i;
|
388
|
+
for (i = 0; i < argc; ++i)
|
389
|
+
rb_ary_push(args, CONVERT_TO_RUBY(runtime, argv[i]));
|
390
|
+
|
391
|
+
JCHECK(call_ruby_from_js(runtime, retval, Johnson_SpiderMonkey_JSLandProxy(),
|
392
|
+
rb_intern("send_with_possible_block"), 3, klass, ID2SYM(rb_intern("new")), args));
|
393
|
+
JRETURN;
|
394
|
+
}
|
395
|
+
|
396
|
+
static JSBool resolve(JSContext *js_context, JSObject *obj, jsval id, uintN UNUSED(flags), JSObject **objp)
|
397
|
+
{
|
398
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
399
|
+
|
400
|
+
JohnsonContext* context;
|
401
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
402
|
+
|
403
|
+
PREPARE_JROOTS(js_context, 1);
|
404
|
+
JROOT(id);
|
405
|
+
|
406
|
+
char* name = JS_GetStringBytes(JS_ValueToString(js_context, id));
|
407
|
+
|
408
|
+
if (respond_to_p(js_context, obj, name))
|
409
|
+
{
|
410
|
+
JCHECK(JS_DefineProperty(js_context, obj, name, JSVAL_VOID,
|
411
|
+
get_and_destroy_resolved_property, set, JSPROP_ENUMERATE));
|
412
|
+
|
413
|
+
*objp = obj;
|
414
|
+
}
|
415
|
+
|
416
|
+
JRETURN;
|
417
|
+
}
|
418
|
+
|
419
|
+
static JSBool to_string(JSContext* js_context, JSObject* obj, uintN UNUSED(argc), jsval* UNUSED(argv), jsval* retval)
|
420
|
+
{
|
421
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
422
|
+
|
423
|
+
JohnsonContext* context;
|
424
|
+
JohnsonRuntime* runtime;
|
425
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
426
|
+
|
427
|
+
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(JS_GetRuntime(js_context));
|
428
|
+
Data_Get_Struct(ruby_runtime, JohnsonRuntime, runtime);
|
429
|
+
|
430
|
+
PREPARE_JROOTS(js_context, 0);
|
431
|
+
|
432
|
+
VALUE self = (VALUE)JS_GetInstancePrivate(context->js, obj, JS_GET_CLASS(context->js, obj), NULL);
|
433
|
+
|
434
|
+
JCHECK(call_ruby_from_js(runtime, retval, self, rb_intern("to_s"), 0));
|
435
|
+
JRETURN;
|
436
|
+
}
|
437
|
+
|
438
|
+
static JSBool to_array(JSContext* js_context, JSObject* obj, uintN UNUSED(argc), jsval* UNUSED(argv), jsval* retval)
|
439
|
+
{
|
440
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
441
|
+
|
442
|
+
JohnsonContext* context;
|
443
|
+
JohnsonRuntime* runtime;
|
444
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
445
|
+
|
446
|
+
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(JS_GetRuntime(js_context));
|
447
|
+
Data_Get_Struct(ruby_runtime, JohnsonRuntime, runtime);
|
448
|
+
|
449
|
+
PREPARE_JROOTS(js_context, 0);
|
450
|
+
|
451
|
+
VALUE self = (VALUE)JS_GetInstancePrivate(context->js, obj, JS_GET_CLASS(context->js, obj), NULL);
|
452
|
+
|
453
|
+
JCHECK(call_ruby_from_js(runtime, retval, self, rb_intern("to_a"), 0));
|
454
|
+
JRETURN;
|
455
|
+
}
|
456
|
+
|
457
|
+
static JSBool method_missing(JSContext* js_context, JSObject* obj, uintN argc, jsval* argv, jsval* retval)
|
458
|
+
{
|
459
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
460
|
+
|
461
|
+
JohnsonContext* context;
|
462
|
+
JohnsonRuntime* runtime;
|
463
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
464
|
+
|
465
|
+
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(JS_GetRuntime(js_context));
|
466
|
+
Data_Get_Struct(ruby_runtime, JohnsonRuntime, runtime);
|
467
|
+
|
468
|
+
PREPARE_JROOTS(js_context, 0);
|
469
|
+
|
470
|
+
VALUE self = (VALUE)JS_GetInstancePrivate(context->js, obj, JS_GET_CLASS(context->js, obj), NULL);
|
471
|
+
|
472
|
+
assert(argc >= 2);
|
473
|
+
|
474
|
+
char* key = JS_GetStringBytes(JSVAL_TO_STRING(argv[0]));
|
475
|
+
VALUE ruby_id = rb_intern(key);
|
476
|
+
|
477
|
+
// FIXME: this is horrible and lazy, to_a comes from enumerable on proxy (argv[1] is a JSArray)
|
478
|
+
VALUE args;
|
479
|
+
JCHECK(call_ruby_from_js2(runtime, &args, CONVERT_TO_RUBY(runtime, argv[1]), rb_intern("to_a"), 0));
|
480
|
+
|
481
|
+
JCHECK(call_ruby_from_js(runtime, retval, Johnson_SpiderMonkey_JSLandProxy(),
|
482
|
+
rb_intern("send_with_possible_block"), 3, self, ID2SYM(ruby_id), args));
|
483
|
+
|
484
|
+
JRETURN;
|
485
|
+
}
|
486
|
+
|
487
|
+
static JSBool call(JSContext* js_context, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* retval)
|
488
|
+
{
|
489
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
490
|
+
|
491
|
+
JohnsonContext* context;
|
492
|
+
JohnsonRuntime* runtime;
|
493
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
494
|
+
|
495
|
+
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(JS_GetRuntime(js_context));
|
496
|
+
Data_Get_Struct(ruby_runtime, JohnsonRuntime, runtime);
|
497
|
+
|
498
|
+
PREPARE_JROOTS(js_context, 0);
|
499
|
+
|
500
|
+
VALUE self = (VALUE)JS_GetInstancePrivate(context->js, JSVAL_TO_OBJECT(JS_ARGV_CALLEE(argv)), &JSLandCallableProxyClass, NULL);
|
501
|
+
|
502
|
+
VALUE args = rb_ary_new();
|
503
|
+
|
504
|
+
uintN i;
|
505
|
+
for (i = 0; i < argc; ++i)
|
506
|
+
rb_ary_push(args, CONVERT_TO_RUBY(runtime, argv[i]));
|
507
|
+
|
508
|
+
JCHECK(call_ruby_from_js(runtime, retval, Johnson_SpiderMonkey_JSLandProxy(),
|
509
|
+
rb_intern("send_with_possible_block"), 3, self, ID2SYM(rb_intern("call")), args));
|
510
|
+
JRETURN;
|
511
|
+
}
|
512
|
+
|
513
|
+
bool js_value_is_proxy(JohnsonRuntime* MAYBE_UNUSED(runtime), jsval maybe_proxy)
|
514
|
+
{
|
515
|
+
JSClass* klass = JS_GET_CLASS(
|
516
|
+
johnson_get_current_context(runtime),
|
517
|
+
JSVAL_TO_OBJECT(maybe_proxy));
|
518
|
+
|
519
|
+
return &JSLandProxyClass == klass
|
520
|
+
|| &JSLandClassProxyClass == klass
|
521
|
+
|| &JSLandCallableProxyClass == klass;
|
522
|
+
}
|
523
|
+
|
524
|
+
VALUE unwrap_js_land_proxy(JohnsonRuntime* runtime, jsval proxy)
|
525
|
+
{
|
526
|
+
VALUE value;
|
527
|
+
JSObject *proxy_object = JSVAL_TO_OBJECT(proxy);
|
528
|
+
JSContext * context = johnson_get_current_context(runtime);
|
529
|
+
|
530
|
+
value = (VALUE)JS_GetInstancePrivate(context, proxy_object,
|
531
|
+
JS_GET_CLASS(context, proxy_object), NULL);
|
532
|
+
|
533
|
+
return value;
|
534
|
+
}
|
535
|
+
|
536
|
+
static void finalize(JSContext* js_context, JSObject* obj)
|
537
|
+
{
|
538
|
+
VALUE ruby_context = (VALUE)JS_GetContextPrivate(js_context);
|
539
|
+
|
540
|
+
if (ruby_context)
|
541
|
+
{
|
542
|
+
JohnsonContext* context;
|
543
|
+
JohnsonRuntime* runtime;
|
544
|
+
Data_Get_Struct(ruby_context, JohnsonContext, context);
|
545
|
+
|
546
|
+
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(JS_GetRuntime(js_context));
|
547
|
+
Data_Get_Struct(ruby_runtime, JohnsonRuntime, runtime);
|
548
|
+
|
549
|
+
VALUE self = (VALUE)JS_GetInstancePrivate(context->js, obj,
|
550
|
+
JS_GET_CLASS(context->js, obj), NULL);
|
551
|
+
|
552
|
+
// remove the proxy OID from the id map
|
553
|
+
JS_HashTableRemove(runtime->rbids, (void *)self);
|
554
|
+
|
555
|
+
// free up the ruby value for GC
|
556
|
+
rb_funcall(ruby_runtime, rb_intern("remove_gcthing"), 1, rb_obj_id(self));
|
557
|
+
}
|
558
|
+
}
|
559
|
+
|
560
|
+
JSBool make_js_land_proxy(JohnsonRuntime* runtime, VALUE value, jsval* retval)
|
561
|
+
{
|
562
|
+
*retval = (jsval)JS_HashTableLookup(runtime->rbids, (void *)value);
|
563
|
+
|
564
|
+
if (*retval)
|
565
|
+
{
|
566
|
+
return JS_TRUE;
|
567
|
+
}
|
568
|
+
else
|
569
|
+
{
|
570
|
+
JSContext * context = johnson_get_current_context(runtime);
|
571
|
+
PREPARE_JROOTS(context, 1);
|
572
|
+
|
573
|
+
JSObject *jsobj;
|
574
|
+
|
575
|
+
JSClass *klass = &JSLandProxyClass;
|
576
|
+
if (T_CLASS == TYPE(value)) klass = &JSLandClassProxyClass;
|
577
|
+
|
578
|
+
// FIXME: hack; should happen in Rubyland
|
579
|
+
if (T_STRUCT == TYPE(value))
|
580
|
+
rb_funcall(Johnson_SpiderMonkey_JSLandProxy(),
|
581
|
+
rb_intern("treat_all_properties_as_methods"), 1, value);
|
582
|
+
|
583
|
+
bool callable_p = Qtrue == rb_funcall(value,
|
584
|
+
rb_intern("respond_to?"), 1, rb_str_new2("call"));
|
585
|
+
|
586
|
+
if (callable_p)
|
587
|
+
klass = &JSLandCallableProxyClass;
|
588
|
+
|
589
|
+
JCHECK((jsobj = JS_NewObject(context, klass, NULL, NULL)));
|
590
|
+
JROOT(jsobj);
|
591
|
+
|
592
|
+
JCHECK(JS_SetPrivate(context, jsobj, (void*)value));
|
593
|
+
|
594
|
+
JCHECK(JS_DefineFunction(context, jsobj, "__noSuchMethod__", method_missing, 2, 0));
|
595
|
+
|
596
|
+
JCHECK(JS_DefineFunction(context, jsobj, "toArray", to_array, 0, 0));
|
597
|
+
JCHECK(JS_DefineFunction(context, jsobj, "toString", to_string, 0, 0));
|
598
|
+
|
599
|
+
*retval = OBJECT_TO_JSVAL(jsobj);
|
600
|
+
|
601
|
+
// put the proxy OID in the id map
|
602
|
+
JCHECK(JS_HashTableAdd(runtime->rbids, (void *)value, (void *)(*retval)));
|
603
|
+
|
604
|
+
// root the ruby value for GC
|
605
|
+
VALUE ruby_runtime = (VALUE)JS_GetRuntimePrivate(runtime->js);
|
606
|
+
rb_funcall(ruby_runtime, rb_intern("add_gcthing"), 1, value);
|
607
|
+
|
608
|
+
JRETURN;
|
609
|
+
}
|
610
|
+
}
|