Permalink
Browse files

Merged up to removal of vendor/spidermonkey.

  • Loading branch information...
matthewd committed Apr 22, 2008
2 parents 97b8244 + 8a7b15c commit bda2acd39ab87cdb080c98acb24a8f9d441c95ee
Showing with 127 additions and 140,057 deletions.
  1. +3 −4 Manifest.txt
  2. +27 −1 ext/spidermonkey/context.c
  3. +7 −30 ext/spidermonkey/js_land_proxy.c
  4. +12 −5 js/{ → johnson}/prelude.js
  5. 0 js/{ → johnson}/template.js
  6. +2 −2 lib/johnson.rb
  7. +56 −0 test/johnson/extensions_test.rb
  8. +20 −0 test/johnson/prelude_test.rb
  9. +0 −15 test/johnson/spidermonkey/js_land_proxy_test.rb
  10. +0 −439 vendor/spidermonkey/Makefile.in
  11. +0 −356 vendor/spidermonkey/Makefile.ref
  12. +0 −824 vendor/spidermonkey/README.html
  13. +0 −12 vendor/spidermonkey/SpiderMonkey.rsp
  14. +0 −19 vendor/spidermonkey/Y.js
  15. +0 −43 vendor/spidermonkey/build.mk
  16. +0 −191 vendor/spidermonkey/config.mk
  17. +0 −65 vendor/spidermonkey/config/AIX4.1.mk
  18. +0 −64 vendor/spidermonkey/config/AIX4.2.mk
  19. +0 −65 vendor/spidermonkey/config/AIX4.3.mk
  20. +0 −83 vendor/spidermonkey/config/Darwin.mk
  21. +0 −81 vendor/spidermonkey/config/Darwin1.3.mk
  22. +0 −41 vendor/spidermonkey/config/Darwin1.4.mk
  23. +0 −81 vendor/spidermonkey/config/Darwin5.2.mk
  24. +0 −81 vendor/spidermonkey/config/Darwin5.3.mk
  25. +0 −77 vendor/spidermonkey/config/HP-UXB.10.10.mk
  26. +0 −77 vendor/spidermonkey/config/HP-UXB.10.20.mk
  27. +0 −80 vendor/spidermonkey/config/HP-UXB.11.00.mk
  28. +0 −87 vendor/spidermonkey/config/IRIX.mk
  29. +0 −44 vendor/spidermonkey/config/IRIX5.3.mk
  30. +0 −44 vendor/spidermonkey/config/IRIX6.1.mk
  31. +0 −44 vendor/spidermonkey/config/IRIX6.2.mk
  32. +0 −44 vendor/spidermonkey/config/IRIX6.3.mk
  33. +0 −44 vendor/spidermonkey/config/IRIX6.5.mk
  34. +0 −103 vendor/spidermonkey/config/Linux_All.mk
  35. +0 −82 vendor/spidermonkey/config/Mac_OS10.0.mk
  36. +0 −72 vendor/spidermonkey/config/OSF1V4.0.mk
  37. +0 −69 vendor/spidermonkey/config/OSF1V5.0.mk
  38. +0 −101 vendor/spidermonkey/config/SunOS4.1.4.mk
  39. +0 −50 vendor/spidermonkey/config/SunOS5.10.mk
  40. +0 −91 vendor/spidermonkey/config/SunOS5.3.mk
  41. +0 −92 vendor/spidermonkey/config/SunOS5.4.mk
  42. +0 −44 vendor/spidermonkey/config/SunOS5.5.1.mk
  43. +0 −87 vendor/spidermonkey/config/SunOS5.5.mk
  44. +0 −89 vendor/spidermonkey/config/SunOS5.6.mk
  45. +0 −44 vendor/spidermonkey/config/SunOS5.7.mk
  46. +0 −44 vendor/spidermonkey/config/SunOS5.8.mk
  47. +0 −44 vendor/spidermonkey/config/SunOS5.9.mk
  48. +0 −117 vendor/spidermonkey/config/WINNT4.0.mk
  49. +0 −117 vendor/spidermonkey/config/WINNT5.0.mk
  50. +0 −117 vendor/spidermonkey/config/WINNT5.1.mk
  51. +0 −117 vendor/spidermonkey/config/WINNT5.2.mk
  52. +0 −117 vendor/spidermonkey/config/WINNT6.0.mk
  53. +0 −64 vendor/spidermonkey/config/dgux.mk
  54. +0 −144 vendor/spidermonkey/editline/Makefile.ref
  55. +0 −83 vendor/spidermonkey/editline/README
  56. +0 −175 vendor/spidermonkey/editline/editline.3
  57. +0 −1,369 vendor/spidermonkey/editline/editline.c
  58. +0 −135 vendor/spidermonkey/editline/editline.h
  59. +0 −182 vendor/spidermonkey/editline/sysunix.c
  60. +0 −82 vendor/spidermonkey/editline/unix.h
  61. +0 −7 vendor/spidermonkey/fdlibm/.cvsignore
  62. +0 −127 vendor/spidermonkey/fdlibm/Makefile.in
  63. +0 −192 vendor/spidermonkey/fdlibm/Makefile.ref
  64. +0 −147 vendor/spidermonkey/fdlibm/e_acos.c
  65. +0 −105 vendor/spidermonkey/fdlibm/e_acosh.c
  66. +0 −156 vendor/spidermonkey/fdlibm/e_asin.c
  67. +0 −165 vendor/spidermonkey/fdlibm/e_atan2.c
  68. +0 −110 vendor/spidermonkey/fdlibm/e_atanh.c
  69. +0 −133 vendor/spidermonkey/fdlibm/e_cosh.c
  70. +0 −202 vendor/spidermonkey/fdlibm/e_exp.c
  71. +0 −184 vendor/spidermonkey/fdlibm/e_fmod.c
  72. +0 −71 vendor/spidermonkey/fdlibm/e_gamma.c
  73. +0 −70 vendor/spidermonkey/fdlibm/e_gamma_r.c
  74. +0 −173 vendor/spidermonkey/fdlibm/e_hypot.c
  75. +0 −524 vendor/spidermonkey/fdlibm/e_j0.c
  76. +0 −523 vendor/spidermonkey/fdlibm/e_j1.c
  77. +0 −315 vendor/spidermonkey/fdlibm/e_jn.c
  78. +0 −71 vendor/spidermonkey/fdlibm/e_lgamma.c
  79. +0 −347 vendor/spidermonkey/fdlibm/e_lgamma_r.c
  80. +0 −184 vendor/spidermonkey/fdlibm/e_log.c
  81. +0 −134 vendor/spidermonkey/fdlibm/e_log10.c
  82. +0 −386 vendor/spidermonkey/fdlibm/e_pow.c
  83. +0 −222 vendor/spidermonkey/fdlibm/e_rem_pio2.c
  84. +0 −120 vendor/spidermonkey/fdlibm/e_remainder.c
  85. +0 −89 vendor/spidermonkey/fdlibm/e_scalb.c
  86. +0 −122 vendor/spidermonkey/fdlibm/e_sinh.c
  87. +0 −497 vendor/spidermonkey/fdlibm/e_sqrt.c
  88. +0 −273 vendor/spidermonkey/fdlibm/fdlibm.h
  89. +0 −1,453 vendor/spidermonkey/fdlibm/fdlibm.mak
  90. BIN vendor/spidermonkey/fdlibm/fdlibm.mdp
  91. +0 −135 vendor/spidermonkey/fdlibm/k_cos.c
  92. +0 −354 vendor/spidermonkey/fdlibm/k_rem_pio2.c
  93. +0 −114 vendor/spidermonkey/fdlibm/k_sin.c
  94. +0 −785 vendor/spidermonkey/fdlibm/k_standard.c
  95. +0 −170 vendor/spidermonkey/fdlibm/k_tan.c
  96. +0 −101 vendor/spidermonkey/fdlibm/s_asinh.c
  97. +0 −175 vendor/spidermonkey/fdlibm/s_atan.c
  98. +0 −133 vendor/spidermonkey/fdlibm/s_cbrt.c
  99. +0 −120 vendor/spidermonkey/fdlibm/s_ceil.c
  100. +0 −72 vendor/spidermonkey/fdlibm/s_copysign.c
  101. +0 −118 vendor/spidermonkey/fdlibm/s_cos.c
  102. +0 −356 vendor/spidermonkey/fdlibm/s_erf.c
  103. +0 −267 vendor/spidermonkey/fdlibm/s_expm1.c
  104. +0 −70 vendor/spidermonkey/fdlibm/s_fabs.c
  105. +0 −71 vendor/spidermonkey/fdlibm/s_finite.c
  106. +0 −121 vendor/spidermonkey/fdlibm/s_floor.c
  107. +0 −99 vendor/spidermonkey/fdlibm/s_frexp.c
  108. +0 −85 vendor/spidermonkey/fdlibm/s_ilogb.c
  109. +0 −74 vendor/spidermonkey/fdlibm/s_isnan.c
  110. +0 −66 vendor/spidermonkey/fdlibm/s_ldexp.c
  111. +0 −73 vendor/spidermonkey/fdlibm/s_lib_version.c
  112. +0 −211 vendor/spidermonkey/fdlibm/s_log1p.c
  113. +0 −79 vendor/spidermonkey/fdlibm/s_logb.c
  114. +0 −64 vendor/spidermonkey/fdlibm/s_matherr.c
  115. +0 −132 vendor/spidermonkey/fdlibm/s_modf.c
  116. +0 −124 vendor/spidermonkey/fdlibm/s_nextafter.c
  117. +0 −131 vendor/spidermonkey/fdlibm/s_rint.c
  118. +0 −107 vendor/spidermonkey/fdlibm/s_scalbn.c
  119. +0 −40 vendor/spidermonkey/fdlibm/s_signgam.c
  120. +0 −68 vendor/spidermonkey/fdlibm/s_significand.c
  121. +0 −118 vendor/spidermonkey/fdlibm/s_sin.c
  122. +0 −112 vendor/spidermonkey/fdlibm/s_tan.c
  123. +0 −122 vendor/spidermonkey/fdlibm/s_tanh.c
  124. +0 −78 vendor/spidermonkey/fdlibm/w_acos.c
  125. +0 −78 vendor/spidermonkey/fdlibm/w_acosh.c
  126. +0 −80 vendor/spidermonkey/fdlibm/w_asin.c
  127. +0 −79 vendor/spidermonkey/fdlibm/w_atan2.c
  128. +0 −81 vendor/spidermonkey/fdlibm/w_atanh.c
  129. +0 −77 vendor/spidermonkey/fdlibm/w_cosh.c
  130. +0 −88 vendor/spidermonkey/fdlibm/w_exp.c
  131. +0 −78 vendor/spidermonkey/fdlibm/w_fmod.c
  132. +0 −85 vendor/spidermonkey/fdlibm/w_gamma.c
  133. +0 −81 vendor/spidermonkey/fdlibm/w_gamma_r.c
  134. +0 −78 vendor/spidermonkey/fdlibm/w_hypot.c
  135. +0 −105 vendor/spidermonkey/fdlibm/w_j0.c
  136. +0 −106 vendor/spidermonkey/fdlibm/w_j1.c
  137. +0 −128 vendor/spidermonkey/fdlibm/w_jn.c
  138. +0 −85 vendor/spidermonkey/fdlibm/w_lgamma.c
  139. +0 −81 vendor/spidermonkey/fdlibm/w_lgamma_r.c
  140. +0 −78 vendor/spidermonkey/fdlibm/w_log.c
  141. +0 −81 vendor/spidermonkey/fdlibm/w_log10.c
  142. +0 −99 vendor/spidermonkey/fdlibm/w_pow.c
  143. +0 −77 vendor/spidermonkey/fdlibm/w_remainder.c
  144. +0 −95 vendor/spidermonkey/fdlibm/w_scalb.c
  145. +0 −77 vendor/spidermonkey/fdlibm/w_sinh.c
  146. +0 −77 vendor/spidermonkey/fdlibm/w_sqrt.c
  147. +0 −73 vendor/spidermonkey/javascript-trace.d
  148. +0 −3,593 vendor/spidermonkey/js.c
  149. +0 −4,344 vendor/spidermonkey/js.mak
  150. BIN vendor/spidermonkey/js.mdp
  151. +0 −305 vendor/spidermonkey/js.msg
  152. +0 −2 vendor/spidermonkey/js.pkg
  153. +0 −79 vendor/spidermonkey/js3240.rc
  154. +0 −654 vendor/spidermonkey/jsOS240.def
  155. +0 −5,728 vendor/spidermonkey/jsapi.c
  156. +0 −2,599 vendor/spidermonkey/jsapi.h
  157. +0 −544 vendor/spidermonkey/jsarena.c
  158. +0 −337 vendor/spidermonkey/jsarena.h
  159. +0 −2,191 vendor/spidermonkey/jsarray.c
  160. +0 −104 vendor/spidermonkey/jsarray.h
  161. +0 −1,043 vendor/spidermonkey/jsatom.c
  162. +0 −447 vendor/spidermonkey/jsatom.h
  163. +0 −232 vendor/spidermonkey/jsbit.h
  164. +0 −176 vendor/spidermonkey/jsbool.c
  165. +0 −73 vendor/spidermonkey/jsbool.h
  166. +0 −139 vendor/spidermonkey/jsclist.h
  167. +0 −1,335 vendor/spidermonkey/jscntxt.c
  168. +0 −1,058 vendor/spidermonkey/jscntxt.h
  169. +0 −57 vendor/spidermonkey/jscompat.h
  170. +0 −246 vendor/spidermonkey/jsconfig.h
  171. +0 −181 vendor/spidermonkey/jsconfig.mk
  172. +0 −380 vendor/spidermonkey/jscpucfg.c
  173. +0 −212 vendor/spidermonkey/jscpucfg.h
  174. +0 −2,382 vendor/spidermonkey/jsdate.c
  175. +0 −124 vendor/spidermonkey/jsdate.h
  176. +0 −1,760 vendor/spidermonkey/jsdbgapi.c
  177. +0 −447 vendor/spidermonkey/jsdbgapi.h
  178. +0 −868 vendor/spidermonkey/jsdhash.c
  179. +0 −592 vendor/spidermonkey/jsdhash.h
  180. +0 −3,167 vendor/spidermonkey/jsdtoa.c
  181. +0 −130 vendor/spidermonkey/jsdtoa.h
  182. +0 −319 vendor/spidermonkey/jsdtracef.c
  183. +0 −77 vendor/spidermonkey/jsdtracef.h
  184. +0 −6,927 vendor/spidermonkey/jsemit.c
  185. +0 −740 vendor/spidermonkey/jsemit.h
  186. +0 −1,361 vendor/spidermonkey/jsexn.c
  187. +0 −96 vendor/spidermonkey/jsexn.h
  188. +0 −2,736 vendor/spidermonkey/jsfile.c
  189. +0 −56 vendor/spidermonkey/jsfile.h
  190. +0 −90 vendor/spidermonkey/jsfile.msg
  191. +0 −2,632 vendor/spidermonkey/jsfun.c
  192. +0 −243 vendor/spidermonkey/jsfun.h
  193. +0 −2,799 vendor/spidermonkey/jsgc.c
  194. +0 −354 vendor/spidermonkey/jsgc.h
  195. +0 −476 vendor/spidermonkey/jshash.c
  196. +0 −151 vendor/spidermonkey/jshash.h
  197. +0 −485 vendor/spidermonkey/jsify.pl
  198. +0 −6,048 vendor/spidermonkey/jsinterp.c
  199. +0 −224 vendor/spidermonkey/jsinterp.h
  200. +0 −1,071 vendor/spidermonkey/jsiter.c
  201. +0 −121 vendor/spidermonkey/jsiter.h
  202. +0 −124 vendor/spidermonkey/jskeyword.tbl
  203. +0 −460 vendor/spidermonkey/jskwgen.c
  204. +0 −266 vendor/spidermonkey/jslibmath.h
  205. +0 −1,322 vendor/spidermonkey/jslock.c
  206. +0 −274 vendor/spidermonkey/jslock.h
  207. +0 −60 vendor/spidermonkey/jslocko.asm
  208. +0 −94 vendor/spidermonkey/jslog2.c
  209. +0 −281 vendor/spidermonkey/jslong.c
  210. +0 −437 vendor/spidermonkey/jslong.h
  211. +0 −518 vendor/spidermonkey/jsmath.c
  212. +0 −57 vendor/spidermonkey/jsmath.h
  213. +0 −1,140 vendor/spidermonkey/jsnum.c
  214. +0 −277 vendor/spidermonkey/jsnum.h
  215. +0 −5,083 vendor/spidermonkey/jsobj.c
  216. +0 −624 vendor/spidermonkey/jsobj.h
  217. +0 −5,082 vendor/spidermonkey/jsopcode.c
  218. +0 −385 vendor/spidermonkey/jsopcode.h
  219. +0 −516 vendor/spidermonkey/jsopcode.tbl
  220. +0 −115 vendor/spidermonkey/jsosdep.h
  221. +0 −202 vendor/spidermonkey/jsotypes.h
  222. +0 −6,628 vendor/spidermonkey/jsparse.c
  223. +0 −513 vendor/spidermonkey/jsparse.h
  224. +0 −1,262 vendor/spidermonkey/jsprf.c
  225. +0 −150 vendor/spidermonkey/jsprf.h
  226. +0 −117 vendor/spidermonkey/jsproto.tbl
  227. +0 −264 vendor/spidermonkey/jsprvtd.h
  228. +0 −744 vendor/spidermonkey/jspubtd.h
  229. +0 −4,325 vendor/spidermonkey/jsregexp.c
  230. +0 −183 vendor/spidermonkey/jsregexp.h
  231. +0 −145 vendor/spidermonkey/jsreops.tbl
  232. +0 −2,000 vendor/spidermonkey/jsscan.c
  233. +0 −387 vendor/spidermonkey/jsscan.h
  234. +0 −1,915 vendor/spidermonkey/jsscope.c
  235. +0 −400 vendor/spidermonkey/jsscope.h
  236. +0 −1,773 vendor/spidermonkey/jsscript.c
  237. +0 −270 vendor/spidermonkey/jsscript.h
  238. +0 −50 vendor/spidermonkey/jsshell.msg
  239. +0 −83 vendor/spidermonkey/jsstddef.h
  240. +0 −5,019 vendor/spidermonkey/jsstr.c
  241. +0 −646 vendor/spidermonkey/jsstr.h
  242. +0 −471 vendor/spidermonkey/jstypes.h
  243. +0 −345 vendor/spidermonkey/jsutil.c
  244. +0 −157 vendor/spidermonkey/jsutil.h
  245. +0 −800 vendor/spidermonkey/jsxdrapi.c
  246. +0 −218 vendor/spidermonkey/jsxdrapi.h
  247. +0 −8,353 vendor/spidermonkey/jsxml.c
  248. +0 −345 vendor/spidermonkey/jsxml.h
  249. +0 −119 vendor/spidermonkey/lock_SunOS.s
  250. +0 −39 vendor/spidermonkey/perfect.js
  251. +0 −36 vendor/spidermonkey/plify_jsdhash.sed
  252. +0 −863 vendor/spidermonkey/prmjtime.c
  253. +0 −103 vendor/spidermonkey/prmjtime.h
  254. +0 −15 vendor/spidermonkey/resource.h
  255. +0 −193 vendor/spidermonkey/rules.mk
  256. +0 −386 vendor/spidermonkey/win32.order
View
@@ -15,16 +15,14 @@ ext/spidermonkey/idhash.h
ext/spidermonkey/immutable_node.c
ext/spidermonkey/immutable_node.c.erb
ext/spidermonkey/immutable_node.h
-ext/spidermonkey/js_function_proxy.c
-ext/spidermonkey/js_function_proxy.h
ext/spidermonkey/js_land_proxy.c
ext/spidermonkey/js_land_proxy.h
ext/spidermonkey/ruby_land_proxy.c
ext/spidermonkey/ruby_land_proxy.h
ext/spidermonkey/spidermonkey.c
ext/spidermonkey/spidermonkey.h
-js/prelude.js
-js/template.js
+js/johnson/prelude.js
+js/johnson/template.js
lib/johnson.rb
lib/johnson/cli/options.rb
lib/johnson/context.rb
@@ -61,6 +59,7 @@ test/johnson/conversions/string_test.rb
test/johnson/conversions/struct_test.rb
test/johnson/conversions/symbol_test.rb
test/johnson/error_test.rb
+test/johnson/extensions_test.rb
test/johnson/nodes/array_literal_test.rb
test/johnson/nodes/array_node_test.rb
test/johnson/nodes/binary_node_test.rb
View
@@ -3,6 +3,8 @@
#include "error.h"
#include "idhash.h"
+static JSBool define_property(JSContext *context, JSObject *obj, uintN argc, jsval *argv, jsval *retval);
+
static VALUE global(VALUE self)
{
OurContext* context;
@@ -111,7 +113,23 @@ static VALUE initialize_native(VALUE self, VALUE options)
JS_SetErrorReporter(context->js, error);
JS_SetContextPrivate(context->js, (void *)self);
- return self;
+ jsval js_cObject;
+ if (JS_GetProperty(context->js, context->global, "Object", &js_cObject)
+ && JS_AddNamedRoot(context->js, &js_cObject, "context.Object")) {
+
+ if (JS_DefineFunction(context->js, JSVAL_TO_OBJECT(js_cObject), "defineProperty", define_property, 4, 0)
+ && JS_DefineProperty(context->js, JSVAL_TO_OBJECT(js_cObject), "READ_ONLY",
+ INT_TO_JSVAL(0x02), NULL, NULL, JSPROP_READONLY)
+ && JS_DefineProperty(context->js, JSVAL_TO_OBJECT(js_cObject), "ITERABLE",
+ INT_TO_JSVAL(0x01), NULL, NULL, JSPROP_READONLY)
+ && JS_DefineProperty(context->js, JSVAL_TO_OBJECT(js_cObject), "NON_DELETABLE",
+ INT_TO_JSVAL(0x04), NULL, NULL, JSPROP_READONLY)) {
+
+ JS_RemoveRoot(context->js, &js_cObject);
+ return self;
+ }
+ JS_RemoveRoot(context->js, &js_cObject);
+ }
}
JS_RemoveRoot(context->js, &(context->global));
}
@@ -131,6 +149,14 @@ static VALUE initialize_native(VALUE self, VALUE options)
rb_raise(rb_eRuntimeError, "Failed to initialize SpiderMonkey context");
}
+// Argv is [ object, name, value, READ_ONLY | ITERABLE | NON_DELETABLE ]
+static JSBool define_property(JSContext *context, JSObject *obj, uintN argc, jsval *argv, jsval *retval) {
+ char *name = JS_GetStringBytes(JSVAL_TO_STRING(argv[1]));
+ int flags = JSVAL_TO_INT(argv[3]);
+
+ return JS_DefineProperty(context, JSVAL_TO_OBJECT(argv[0]), name, argv[2], NULL, NULL, flags);
+}
+
void init_Johnson_SpiderMonkey_Context(VALUE spidermonkey)
{
VALUE context = rb_define_class_under(spidermonkey, "Context", rb_cObject);
@@ -122,6 +122,12 @@ static bool respond_to_p(JSContext* js_context, JSObject* obj, char* name)
|| has_key_p(self, name);
}
+static jsval evaluate_js_property_expression(OurContext * context, char * property, jsval* retval) {
+ return JS_EvaluateScript(context->js, context->global,
+ property, strlen(property), "johnson:evaluate_js_property_expression", 1,
+ retval);
+}
+
static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
{
JS_AddNamedRoot(js_context, &id, "JSLandProxy#get");
@@ -159,39 +165,10 @@ static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
JS_RemoveRoot(js_context, &id);
- // FIXME: this is necessarily ugly. Maybe we should write something like
- // jsval foo = property_expression(context->js, context->global, "Johnson.Generator.create")
- // this would make the code where we look up Johnson.Symbol cleaner too (in conversions.c)
-
// FIXME: we should probably just JS_DefineProperty this, and it shouldn't be enumerable
if (!strcasecmp("__iterator__", name)) {
- jsval nsJohnson;
- if(!(JS_GetProperty(context->js, context->global, "Johnson", &nsJohnson)))
- return JS_FALSE;
-
- JS_AddNamedRoot(context->js, &nsJohnson, "JSLandProxy#get");
-
- jsval nsGenerator;
- if(!(JS_GetProperty(context->js, JSVAL_TO_OBJECT(nsJohnson), "Generator", &nsGenerator))) {
- JS_RemoveRoot(context->js, &nsJohnson);
- return JS_FALSE;
- }
-
- JS_AddNamedRoot(context->js, &nsGenerator, "JSLandProxy#get");
-
- jsval create;
- if(!(JS_GetProperty(context->js, JSVAL_TO_OBJECT(nsGenerator), "create", &create))) {
- JS_RemoveRoot(context->js, &nsGenerator);
- JS_RemoveRoot(context->js, &nsJohnson);
- return JS_FALSE;
- }
-
- JS_RemoveRoot(context->js, &nsGenerator);
- JS_RemoveRoot(context->js, &nsJohnson);
-
- *retval = create;
- return JS_TRUE;
+ return evaluate_js_property_expression(context, "Johnson.Generator.create", retval);
}
// if the Ruby object has a dynamic js property with a key
@@ -41,16 +41,23 @@ Johnson.Generator.create = function() {
Johnson.required = {};
Johnson.require = function(file) {
+ file = Ruby.File.join(Ruby.File.dirname(file),
+ Ruby.File.basename(file, ".js") + ".js");
+
if(Johnson.required[file]) return false;
- for(var directory in Ruby['$LOAD_PATH']) {
- var filename = directory + "/" + Ruby.File.basename(file, ".js") + ".js";
- if(Ruby.File['exists?'](filename)) {
+
+ for(var directory in Ruby["$LOAD_PATH"]) {
+ var path = Ruby.File.join(directory, file);
+
+ if(Ruby.File.send("file?", path)) {
Johnson.required[file] = true;
- eval(Ruby.File.read(filename));
+ eval(Ruby.File.read(path));
+
return true;
}
}
- throw FileNotFound;
+
+ throw LoadError;
}
null; // no need to marshal a result
File renamed without changes.
View
@@ -25,10 +25,10 @@
require "johnson/context"
require "johnson/parser"
-$LOAD_PATH.push File.expand_path("#{File.dirname(__FILE__)}/../js")
+$LOAD_PATH.push(File.expand_path("#{File.dirname(__FILE__)}/../js"))
module Johnson
- PRELUDE = IO.read(File.dirname(__FILE__) + "/../js/prelude.js")
+ PRELUDE = IO.read(File.dirname(__FILE__) + "/../js/johnson/prelude.js")
def self.evaluate(expression, vars={})
context = Johnson::Context.new
@@ -0,0 +1,56 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "/../helper"))
+
+module Johnson
+ module Extensions
+ class DefinePropertyTest < Johnson::TestCase
+ def setup
+ @context = Johnson::Context.new
+ @context.evaluate("x = {}")
+ end
+
+ def test_object_can_define_property
+ @context.evaluate("Object.defineProperty(x, 'answer', 42)")
+ assert_js_equal(42, "x.answer")
+ end
+
+ def test_object_can_define_unenumerable_property
+ @context.evaluate("Object.defineProperty(x, 'answer', 42)")
+ @context.evaluate <<-JS
+ y = [];
+ for(prop in x) if(prop == "answer") y.push(prop)
+ JS
+ assert_js("y.length == 0")
+ end
+
+ def test_object_can_define_enumerable_property
+ @context.evaluate("Object.defineProperty(x, 'answer', 42, Object.ITERABLE)")
+ @context.evaluate <<-JS
+ y = [];
+ for(prop in x) if(prop == "answer") y.push(prop)
+ JS
+ assert_js("y.length == 1")
+ end
+
+ def test_object_can_define_read_only_property
+ @context.evaluate("Object.defineProperty(x, 'answer', 42, Object.READ_ONLY)")
+ @context.evaluate("x.answer = 47")
+ assert_js_equal(42, "x.answer")
+ end
+
+ def test_object_can_define_non_deletable_property
+ @context.evaluate("Object.defineProperty(x, 'answer', 42, Object.NON_DELETABLE)")
+ @context.evaluate("r = (delete x.answer)")
+ assert_js_equal(false, "r")
+ assert_js_equal(42, "x.answer")
+ end
+
+ def test_object_can_define_mixed_property
+ @context.evaluate("Object.defineProperty(x, 'answer', 42, Object.NON_DELETABLE | Object.READ_ONLY)")
+ @context.evaluate("r = (delete x.answer)")
+ @context.evaluate("x.answer = 47")
+ assert_js_equal(false, "r")
+ assert_js_equal(42, "x.answer")
+ end
+ end
+ end
+end
@@ -24,5 +24,25 @@ def test_all_of_ruby_is_available
@context.evaluate("Ruby.require('set')")
assert_kind_of(Set, @context.evaluate("Ruby.Set.new()"))
end
+
+ def test_require_an_existing_js_file_without_extension
+ assert_js("Johnson.require('johnson/template')")
+ end
+
+ def test_require_returns_false_the_second_time_around
+ assert_js("Johnson.require('johnson/template')")
+ assert(!@context.evaluate("Johnson.require('johnson/template')"))
+ end
+
+ def test_missing_requires_throw_LoadError
+ assert_js(<<-END)
+ var flag = false;
+
+ try { Johnson.require("johnson/__nonexistent"); }
+ catch(FileNotFound) { flag = true; }
+
+ flag;
+ END
+ end
end
end
@@ -65,21 +65,6 @@ def test_find_constants
assert_js_equal($LOAD_PATH, "Ruby['$LOAD_PATH']")
end
- def test_require_twice
- assert @context.evaluate('Johnson.require("prelude")')
- assert !@context.evaluate('Johnson.require("prelude")')
- end
-
- def test_catch_missing_require
- assert @context.evaluate("
- try {
- Johnson.require('adkfjhasd');
- } catch(FileNotFound) {
- true;
- }
- ")
- end
-
def test_proxies_get_reused
@context["foo"] = @context["bar"] = Foo.new
assert_js_equal(true, "foo === bar")
Oops, something went wrong.

0 comments on commit bda2acd

Please sign in to comment.