From e18f74d831b40dba2181c6d70729c7ef46b4044f Mon Sep 17 00:00:00 2001 From: John Barnette Date: Mon, 14 Apr 2008 22:08:12 -0700 Subject: [PATCH] Renaming proxies for clarity. --- Manifest.txt | 188 +++++++++++++++++- ext/spidermonkey/conversions.c | 14 +- ext/spidermonkey/js_function_proxy.c | 2 +- .../{js_proxy.c => js_land_proxy.c} | 24 +-- ext/spidermonkey/js_land_proxy.h | 13 ++ ext/spidermonkey/js_proxy.h | 13 -- .../{ruby_proxy.c => ruby_land_proxy.c} | 60 +++--- ext/spidermonkey/ruby_land_proxy.h | 16 ++ ext/spidermonkey/ruby_proxy.h | 16 -- ext/spidermonkey/spidermonkey.c | 2 +- lib/johnson.rb | 2 +- lib/johnson/spidermonkey/context.rb | 20 +- .../{ruby_proxy.rb => ruby_land_proxy.rb} | 2 +- test/johnson/spidermonkey/js_proxy_test.rb | 2 +- ..._proxy_test.rb => ruby_land_proxy_test.rb} | 12 +- 15 files changed, 281 insertions(+), 105 deletions(-) rename ext/spidermonkey/{js_proxy.c => js_land_proxy.c} (93%) create mode 100644 ext/spidermonkey/js_land_proxy.h delete mode 100644 ext/spidermonkey/js_proxy.h rename ext/spidermonkey/{ruby_proxy.c => ruby_land_proxy.c} (84%) create mode 100644 ext/spidermonkey/ruby_land_proxy.h delete mode 100644 ext/spidermonkey/ruby_proxy.h rename lib/johnson/spidermonkey/{ruby_proxy.rb => ruby_land_proxy.rb} (97%) rename test/johnson/spidermonkey/{ruby_proxy_test.rb => ruby_land_proxy_test.rb} (92%) diff --git a/Manifest.txt b/Manifest.txt index 30dcbf9..b47ae40 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -1,3 +1,176 @@ +.git/COMMIT_EDITMSG +.git/FETCH_HEAD +.git/HEAD +.git/ORIG_HEAD +.git/config +.git/description +.git/hooks/applypatch-msg +.git/hooks/commit-msg +.git/hooks/post-commit +.git/hooks/post-receive +.git/hooks/post-update +.git/hooks/pre-applypatch +.git/hooks/pre-commit +.git/hooks/pre-rebase +.git/hooks/update +.git/index +.git/info/exclude +.git/logs/HEAD +.git/logs/refs/heads/land +.git/logs/refs/heads/master +.git/logs/refs/remotes/origin/master +.git/logs/refs/remotes/rubyforge/master +.git/objects/01/48bb906f4eccf114be5f05205f8a147d957f1f +.git/objects/02/0cb13da2f13db04883a151b691262e51f343dd +.git/objects/02/2d39d9b9b2615d3ecdc977cc8ff96beb4010e0 +.git/objects/02/5b784c719191e7ea10abd856c15931c9cb47b8 +.git/objects/02/b6e6345a24a767164fb01050aa3fba079bb47d +.git/objects/04/7671212be5c21d26a83a274e909a16f08340d9 +.git/objects/05/6af4b282b7942633a41131cf63b2e1edb2e580 +.git/objects/06/78289f22add0aeb7fb9dec4972aac1bb478ea9 +.git/objects/0b/192fe8b9651237d974c4c6d288f460b2a2e063 +.git/objects/0c/fd007139c69c3f994490eb0192970deeb9aaf3 +.git/objects/0d/e05b2f9ecde3ac72ad724925a089b624745afe +.git/objects/10/3afc8fe3b2d1ac4c14ffa68b9353a16f9965cc +.git/objects/11/8f9e74a2721e4d52b2250dbc7d142e5c52e9ae +.git/objects/13/f40d948dfc2b65589dc9f75bbef9bb0fb1d63e +.git/objects/14/b9989bc735b2cb5a059f17434210b9c6bf4f55 +.git/objects/15/c05b4ac5b935df48d6c00ee6e402ae3b2fd0b8 +.git/objects/1a/10c99ed633dafaa3a1c90c003a5ed1d69c9c7f +.git/objects/1a/ea38741ee2972ffb60beacb5f54adf322add8f +.git/objects/1b/ba7d103bc50ec4e129add6b9d65ac6af010e1d +.git/objects/1e/966b1a8bc54602ea4f1c76689c04897663c2d9 +.git/objects/1f/5686a0a6a6b2467721fb5e319b50e2a8deebe5 +.git/objects/20/2282a39f8736544bba8d15d708282dc83407fd +.git/objects/20/4c021151b5af07d323e257c4a07dde3728015a +.git/objects/20/d4a1f2af38e0a090bad7b46a653267deb47e0d +.git/objects/25/2b95371a7237a0a0416ba0bc95e6cbd086ca63 +.git/objects/26/b1621d4d3fee298e76a0ad08391536aa11d68e +.git/objects/28/a378edb6d20fbf7112da139f50572d2e526ed0 +.git/objects/29/031f141dd7e7afe01780fafd8d7e7ca156aaaa +.git/objects/29/5ccd49afcf9bf34c450d72e419055e2c42c119 +.git/objects/2b/80531e7a4d07c87d3013bd2500d10f4ce497fa +.git/objects/2c/b155d53b034816adde2f7b86602862988228f5 +.git/objects/30/66113f3e53f702ad2d9de1419def78e7b7412a +.git/objects/32/45a70b585f25b457f2d356ddaa4ed5690a9c1e +.git/objects/34/55325234f0f4cb9281f49d5bbc46acf671368a +.git/objects/36/1fd5ce85ab9932473ca737676ff33a8639e093 +.git/objects/39/0c11e0e43aca00be24850ed7258134ce2bd8cc +.git/objects/3a/f013bbb38c98401bc982f1dfb2daac5749017c +.git/objects/3b/fd36028d85ba12ac9ada216b5ec779dd9774ae +.git/objects/3d/fa60866cc1d00fe26452f5fd0f8d5c49a3fbb5 +.git/objects/3e/00c63bc4582b3754e42e787ce011612fd6ab52 +.git/objects/3f/764f94f20d8820bd00dad9d898f28a26371a3c +.git/objects/40/e6446b07541e21125d2264051e4937264dfa50 +.git/objects/41/f4dd6ba2ed8f690d85e8cd8118e0198fe67520 +.git/objects/44/fb99cbeb963834728fd58eceeb5e5a429ca6bc +.git/objects/45/6a8a587c94cf170534efbc0fcfd040379426b1 +.git/objects/4a/02ec820b43e733ad5ea676b3bb5257aa18400b +.git/objects/4a/8c225c7acb281b0cd3ae9243be93e42a2f89ab +.git/objects/4a/8e9fddb7bc9fb8f858af2e11a4f0103b605cf1 +.git/objects/4b/0fe7e60d46a6816e52f708c9b0d1120650b239 +.git/objects/4b/2eb091ad3d165095b938924beb6981152e1131 +.git/objects/4c/0eecadb6ba06ba00fe00453f39ec96b4e4291c +.git/objects/4c/dd33e232a7ecaaff0cd52c1d0e9518d67991b8 +.git/objects/4e/694d5db90362ad857da7105bbb3cb3d4cf1a6e +.git/objects/50/95989a8a4a86ee8f734e24b4388737ac061cc9 +.git/objects/51/214456e042ff575ef1a5722115c9fb3350429d +.git/objects/56/3fa073d6e6647a5f7c21abb1d492c32db1830a +.git/objects/59/64f724c49ad3ea66d1a0dd893d049a695431ea +.git/objects/5a/fc327300d9175030714a6410da2e27e54e11ee +.git/objects/5c/8e0164263f190d1531f63819560ab7254f5db7 +.git/objects/5f/f66c6c79a2715e070eb3c542ac29352a621d95 +.git/objects/60/48f0b0e0b446bec997d9e00e9752a4f43f04a8 +.git/objects/64/5bdee7621992223d69e8c1adc0893b4f09e408 +.git/objects/64/7421969e95dde4e493ae71fa42f310e6ac29fd +.git/objects/6b/4a11759336ad3860d9e1f2db082acf3890fe82 +.git/objects/6e/82de62db71c41dbc2dd30a968974b0c39ea378 +.git/objects/70/09f383c20c7ba8e45a913d5572a39123ee0680 +.git/objects/70/84c0026198055c60aa8f819f13933111751ee7 +.git/objects/71/46cb6dae61c591fba9a62d128762c132d607b1 +.git/objects/71/4af57daa536c480e7f2e48deb91bea23f29020 +.git/objects/73/29bb592deca42946f4c0262925107a385ef52b +.git/objects/74/93cdc15a0b3d220c4169a2eba14185dcf1443f +.git/objects/74/9487fe6bbab324edacbd698eff75397e9dd4d3 +.git/objects/74/9f2b227592896e505ae25f8ebc630ac925813a +.git/objects/76/e3bb73d92a705e570a3c6733b40fddef2eb88d +.git/objects/78/6638aafa27bb996d83f7e179ad658bf51776aa +.git/objects/7b/07078231fbea945efd4a9552c735e9efe7ee15 +.git/objects/7c/70e23a78a2d358630b9933047dadc10aaccbcb +.git/objects/7d/421f8e30de783832b5b6677321bfc2dac56c45 +.git/objects/7d/e0432a931c1dc613c3829f93accb0f8f3ef2d3 +.git/objects/7e/064dd15f00c3853d7c60d22f99af5c76e5240f +.git/objects/7e/d8faa771a90d739e721440e91c8e65ee5cd5b9 +.git/objects/7f/fa4927e711a513f961a46c1d22fce241eaf621 +.git/objects/81/954cd97ec0c53887e19fa7a67cb0886f571b96 +.git/objects/82/b9e0a192164748c6e52e8af5f58ae21d9193a0 +.git/objects/84/fc38d8f4215ee75a56acbf7f427f252fcf29a8 +.git/objects/89/2a013ca72b15beb894a31cc8ffab4f2cc3223e +.git/objects/89/4631f502017b7a25153c9521fb93381f228b92 +.git/objects/8b/fd4112db605bcab8f7874c07eb1e8ed4809f3d +.git/objects/8c/ba3d0672c1e1b3eadbb669481a8a82c30b667a +.git/objects/8f/2654fed272d821ce4b37747276df1e57e2d200 +.git/objects/90/1aeaa651d23e60f0a1888dc7b80d1d2bd10426 +.git/objects/90/783159799de6d1c0dc8dbf63f069d939052815 +.git/objects/90/b50f25d5beb527cc0c7fd0979fea0c6672d911 +.git/objects/92/aa743f2111bd235332ab6015224332a84e822b +.git/objects/96/80a8d375f20ab7f2aa7b2dd88a6319470ae045 +.git/objects/97/8928c55d1cfe1e678c58f2647c547ec5c314ba +.git/objects/98/46dcdabcbdfa723be92111cdc621824021583c +.git/objects/99/e33df07f9a6e9f5929a511e267c09d357df839 +.git/objects/9e/4f6d88547a15ae662363eaec4112117013f6d4 +.git/objects/9f/303234cf70acdd03dc91d0cf85f46755924f0b +.git/objects/a2/51de94fe4b9fc2184d31b950a68e6ea1e503cb +.git/objects/a2/de38ad7d41b5f645360a6ca251a94adb69f7ee +.git/objects/a7/37637c7bc2a6b4f1f2679debafe878c08675fd +.git/objects/a9/1407579be00fffe7d32f16b28320e1968bb0f0 +.git/objects/aa/ed3fa0979c3af0aa56bc40ed2d7272dde25850 +.git/objects/aa/fba89b70dde45a9bfc92ef08f87f20ed4312cc +.git/objects/ac/e54c77a1f639180d8e292de9d6dee5b01d1cd7 +.git/objects/af/001acee62b58d61d9bd70a95fee6d18ab09f70 +.git/objects/b4/174cc409243996a308385784bb77ff131b3d99 +.git/objects/b7/45677cd9a865c6da79bb78b22c6fc838a8913b +.git/objects/be/3790f6fe8a22f08aea821054111582453ff758 +.git/objects/c0/b87f3781f46879b2df76b53ba67774817bc8ee +.git/objects/c4/1a455b4d4f626363e9b46e477c17d6b06b521d +.git/objects/c6/d3602347c205552f111a197fcd9f92a7d55e26 +.git/objects/c9/93f1e28764c2cbd1ba27f42ac66d81ab245c26 +.git/objects/c9/a67e70997de49f65b6da2e18e2ef3965b07e8f +.git/objects/ca/ac974ebb042ea0dd9da7bbab985eae5abaeffa +.git/objects/ca/c073a4e0d2791707ce373f12690df506992449 +.git/objects/ca/c077eb6b6fe542b457898b39168a12e1295102 +.git/objects/cd/05d0ec89b37a502b70b3b000311a41eb6e540e +.git/objects/cd/0b3f9d1f10ba0da1cc65884c6d8cf0e5762a5e +.git/objects/d0/4f0baffd8bbe84054f9793f17cf335085a2a9e +.git/objects/d3/5c5b10d93779b48df3828cbdcbe3386889351e +.git/objects/d7/7008ca1254473dab963f793f96fe3954961b33 +.git/objects/d7/da104ce1d145e8e49b6e8def4c03473af02fb2 +.git/objects/d9/25514bfaf5819f1d38e2af1042fb0087fa504f +.git/objects/d9/34c0d551e100ad18c9b1621830ea572afaf237 +.git/objects/d9/541bb110f9194f4a29eb1f748c4a0cdcaa1e32 +.git/objects/d9/5e3507e30b11da60358cbafbf94c264f192b48 +.git/objects/de/1dca6881cf5aeb50420cced48fb259787d22f0 +.git/objects/ea/3d505a5ee9e5de4d1115c067f6e3b2abcddfc8 +.git/objects/ec/98b29568308dc3e86448d78e7ad566a3aab933 +.git/objects/ec/ae4a4717f8963d4cfbc27dd9b7d4ad83bc7289 +.git/objects/ee/925ba2c4dc26196570d33ef39f984def149791 +.git/objects/ef/0d3ecb3b29db617ccb1d1b640648634bb6d44c +.git/objects/ef/297179115240aeae87c08f6b642c55c118a732 +.git/objects/f0/4cc7f159c194e4ec73f52f943321fda6fd8799 +.git/objects/f0/eb6c18d20b0403ac229f0e610e13588d5e904c +.git/objects/f5/85d6fa657e1d0a190378557ba54f722f93bf60 +.git/objects/f6/d9e730f51b4a45e9e09e9390837d67f9a56545 +.git/objects/f8/339c463aa5509aed0007a0347a5a3c022af5b9 +.git/objects/fc/7b1afcb483957d7d2c368d3e5b0d4c5f494a57 +.git/objects/fe/1902b763f63caaf8aa780c7085de3fe4f7d4e1 +.git/objects/pack/pack-5176ed4356c57ad85d57004c271113e224145786.idx +.git/objects/pack/pack-5176ed4356c57ad85d57004c271113e224145786.pack +.git/refs/heads/land +.git/refs/heads/master +.git/refs/remotes/origin/HEAD +.git/refs/remotes/origin/master +.git/refs/remotes/rubyforge/master +.gitignore History.txt Manifest.txt README.txt @@ -16,10 +189,10 @@ 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_proxy.c -ext/spidermonkey/js_proxy.h -ext/spidermonkey/ruby_proxy.c -ext/spidermonkey/ruby_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 lib/johnson.rb @@ -36,7 +209,7 @@ lib/johnson/parser.rb lib/johnson/spidermonkey/context.rb lib/johnson/spidermonkey/immutable_node.rb lib/johnson/spidermonkey/mutable_tree_visitor.rb -lib/johnson/spidermonkey/ruby_proxy.rb +lib/johnson/spidermonkey/ruby_land_proxy.rb lib/johnson/version.rb lib/johnson/visitable.rb lib/johnson/visitors.rb @@ -46,10 +219,13 @@ lib/prelude.js test/helper.rb test/johnson/context_test.rb test/johnson/conversions/boolean_test.rb +test/johnson/conversions/file_test.rb test/johnson/conversions/nil_test.rb test/johnson/conversions/number_test.rb test/johnson/conversions/proc_test.rb +test/johnson/conversions/regexp_test.rb 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/nodes/array_literal_test.rb @@ -81,7 +257,7 @@ test/johnson/prelude_test.rb test/johnson/spidermonkey/context_test.rb test/johnson/spidermonkey/immutable_node_test.rb test/johnson/spidermonkey/js_proxy_test.rb -test/johnson/spidermonkey/ruby_proxy_test.rb +test/johnson/spidermonkey/ruby_land_proxy_test.rb test/johnson/version_test.rb test/johnson_test.rb test/parser_test.rb diff --git a/ext/spidermonkey/conversions.c b/ext/spidermonkey/conversions.c index d95e350..e73ec2a 100644 --- a/ext/spidermonkey/conversions.c +++ b/ext/spidermonkey/conversions.c @@ -1,7 +1,7 @@ #include "conversions.h" -#include "js_proxy.h" +#include "js_land_proxy.h" #include "js_function_proxy.h" -#include "ruby_proxy.h" +#include "ruby_land_proxy.h" static jsval convert_float_or_bignum_to_js(OurContext* context, VALUE float_or_bignum) { @@ -69,14 +69,14 @@ jsval convert_to_js(OurContext* context, VALUE ruby) case T_FILE: case T_STRUCT: case T_OBJECT: - return make_js_proxy(context, ruby); + return make_js_land_proxy(context, ruby); case T_REGEXP: return convert_regexp_to_js(context, ruby); case T_DATA: // HEY! keep T_DATA last for fall-through if (ruby_value_is_proxy(ruby)) - return unwrap_ruby_proxy(context, ruby); + return unwrap_ruby_land_proxy(context, ruby); if (rb_cProc == CLASS_OF(ruby)) return make_js_function_proxy(context, ruby); @@ -140,19 +140,19 @@ VALUE convert_to_ruby(OurContext* context, jsval js) case JSTYPE_OBJECT: if (OBJECT_TO_JSVAL(context->global) == js) // global gets special treatment, since the Prelude might not be loaded - return make_ruby_proxy(context, js); + return make_ruby_land_proxy(context, js); // this conditional requires the Prelude if (js_value_is_symbol(context, js)) return ID2SYM(rb_intern(JS_GetStringBytes(JS_ValueToString(context->js, js)))); if (js_value_is_proxy(context, js)) - return unwrap_js_proxy(context, js); + return unwrap_js_land_proxy(context, js); if (js_value_is_a_regexp(context, js)) return make_ruby_regexp(context, js); - return make_ruby_proxy(context, js); + return make_ruby_land_proxy(context, js); case JSTYPE_BOOLEAN: return JSVAL_TRUE == js ? Qtrue : Qfalse; diff --git a/ext/spidermonkey/js_function_proxy.c b/ext/spidermonkey/js_function_proxy.c index a3075a5..59b036f 100644 --- a/ext/spidermonkey/js_function_proxy.c +++ b/ext/spidermonkey/js_function_proxy.c @@ -78,7 +78,7 @@ jsval make_js_function_proxy(OurContext* context, VALUE proc) assert(JS_HashTableAdd(context->rbids, (void *)rb_obj_id(proc), (void *)newid)); // root the ruby value for GC - // FIXME: this is pretty much copy/paste from js_proxy.c + // FIXME: this is pretty much copy/paste from js_land_proxy.c // FIXME: no custom finalizer on JSFunction, so never freed! VALUE ruby_context = (VALUE)JS_GetContextPrivate(context->js); rb_funcall(ruby_context, rb_intern("add_gcthing"), 1, proc); diff --git a/ext/spidermonkey/js_proxy.c b/ext/spidermonkey/js_land_proxy.c similarity index 93% rename from ext/spidermonkey/js_proxy.c rename to ext/spidermonkey/js_land_proxy.c index 6048f0b..45ec490 100644 --- a/ext/spidermonkey/js_proxy.c +++ b/ext/spidermonkey/js_land_proxy.c @@ -1,11 +1,11 @@ -#include "js_proxy.h" +#include "js_land_proxy.h" static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval); static void finalize(JSContext* context, JSObject* obj); static JSBool set(JSContext* context, JSObject* obj, jsval id, jsval* retval); -static JSClass JSProxyClass = { - "JSProxy", JSCLASS_HAS_PRIVATE, +static JSClass ProxyInJSClass = { + "ProxyInJS", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_PropertyStub, get, @@ -31,7 +31,7 @@ static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval) // get the Ruby object that backs this proxy VALUE self; - assert(self = (VALUE)JS_GetInstancePrivate(context->js, obj, &JSProxyClass, NULL)); + assert(self = (VALUE)JS_GetInstancePrivate(context->js, obj, &ProxyInJSClass, NULL)); char* key = JS_GetStringBytes(JSVAL_TO_STRING(id)); VALUE ruby_id = rb_intern(key); @@ -92,7 +92,7 @@ static JSBool set(JSContext* js_context, JSObject* obj, jsval id, jsval* value) Data_Get_Struct(ruby_context, OurContext, context); VALUE self; - assert(self = (VALUE)JS_GetInstancePrivate(context->js, obj, &JSProxyClass, NULL)); + assert(self = (VALUE)JS_GetInstancePrivate(context->js, obj, &ProxyInJSClass, NULL)); char* key = JS_GetStringBytes(JSVAL_TO_STRING(id)); VALUE ruby_key = rb_str_new2(key); @@ -137,7 +137,7 @@ static JSBool method_missing(JSContext* js_context, JSObject* obj, uintN argc, j Data_Get_Struct(ruby_context, OurContext, context); VALUE self; - assert(self = (VALUE)JS_GetInstancePrivate(context->js, obj, &JSProxyClass, NULL)); + assert(self = (VALUE)JS_GetInstancePrivate(context->js, obj, &ProxyInJSClass, NULL)); char* key = JS_GetStringBytes(JSVAL_TO_STRING(argv[0])); @@ -156,13 +156,13 @@ static JSBool method_missing(JSContext* js_context, JSObject* obj, uintN argc, j JSBool js_value_is_proxy(OurContext* context, jsval maybe_proxy) { - return JS_InstanceOf(context->js, JSVAL_TO_OBJECT(maybe_proxy), &JSProxyClass, NULL); + return JS_InstanceOf(context->js, JSVAL_TO_OBJECT(maybe_proxy), &ProxyInJSClass, NULL); } -VALUE unwrap_js_proxy(OurContext* context, jsval proxy) +VALUE unwrap_js_land_proxy(OurContext* context, jsval proxy) { VALUE value; - assert(value = (VALUE)JS_GetInstancePrivate(context->js, JSVAL_TO_OBJECT(proxy), &JSProxyClass, NULL)); + assert(value = (VALUE)JS_GetInstancePrivate(context->js, JSVAL_TO_OBJECT(proxy), &ProxyInJSClass, NULL)); return value; } @@ -176,7 +176,7 @@ static void finalize(JSContext* js_context, JSObject* obj) Data_Get_Struct(ruby_context, OurContext, context); VALUE self; - assert(self = (VALUE)JS_GetInstancePrivate(context->js, obj, &JSProxyClass, NULL)); + assert(self = (VALUE)JS_GetInstancePrivate(context->js, obj, &ProxyInJSClass, NULL)); // remove the proxy OID from the id map JS_HashTableRemove(context->rbids, (void *)rb_obj_id(self)); @@ -186,7 +186,7 @@ static void finalize(JSContext* js_context, JSObject* obj) } } -jsval make_js_proxy(OurContext* context, VALUE value) +jsval make_js_land_proxy(OurContext* context, VALUE value) { jsid id = (jsid)JS_HashTableLookup(context->rbids, (void *)rb_obj_id(value)); jsval js; @@ -199,7 +199,7 @@ jsval make_js_proxy(OurContext* context, VALUE value) { JSObject *jsobj; - assert(jsobj = JS_NewObject(context->js, &JSProxyClass, NULL, NULL)); + assert(jsobj = JS_NewObject(context->js, &ProxyInJSClass, NULL, NULL)); assert(JS_SetPrivate(context->js, jsobj, (void*)value)); assert(JS_DefineFunction(context->js, jsobj, "__noSuchMethod__", method_missing, 2, 0)); diff --git a/ext/spidermonkey/js_land_proxy.h b/ext/spidermonkey/js_land_proxy.h new file mode 100644 index 0000000..3374a78 --- /dev/null +++ b/ext/spidermonkey/js_land_proxy.h @@ -0,0 +1,13 @@ +#ifndef JOHNSON_SPIDERMONKEY_JS_LAND_PROXY_H +#define JOHNSON_SPIDERMONKEY_JS_LAND_PROXY_H + +#include "spidermonkey.h" +#include "context.h" + +#define JS_FUNCTION_PROXY_PROPERTY "__isProxyForRubyProc" + +JSBool js_value_is_proxy(OurContext* context, jsval maybe_proxy); +VALUE unwrap_js_land_proxy(OurContext* context, jsval proxy); +jsval make_js_land_proxy(OurContext* context, VALUE value); + +#endif diff --git a/ext/spidermonkey/js_proxy.h b/ext/spidermonkey/js_proxy.h deleted file mode 100644 index 3a254a7..0000000 --- a/ext/spidermonkey/js_proxy.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef JOHNSON_SPIDERMONKEY_JS_PROXY_H -#define JOHNSON_SPIDERMONKEY_JS_PROXY_H - -#include "spidermonkey.h" -#include "context.h" - -#define JS_FUNCTION_PROXY_PROPERTY "__isProxyForRubyProc" - -JSBool js_value_is_proxy(OurContext* context, jsval maybe_proxy); -VALUE unwrap_js_proxy(OurContext* context, jsval proxy); -jsval make_js_proxy(OurContext* context, VALUE value); - -#endif diff --git a/ext/spidermonkey/ruby_proxy.c b/ext/spidermonkey/ruby_land_proxy.c similarity index 84% rename from ext/spidermonkey/ruby_proxy.c rename to ext/spidermonkey/ruby_land_proxy.c index 9f30323..ee142dd 100644 --- a/ext/spidermonkey/ruby_proxy.c +++ b/ext/spidermonkey/ruby_land_proxy.c @@ -1,4 +1,4 @@ -#include "ruby_proxy.h" +#include "ruby_land_proxy.h" static VALUE proxy_class = Qnil; @@ -7,8 +7,8 @@ get(VALUE self, VALUE name) { Check_Type(name, T_STRING); - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); jsval js_value; @@ -23,8 +23,8 @@ set(VALUE self, VALUE name, VALUE value) { Check_Type(name, T_STRING); - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); jsval js_value = convert_to_js(proxy->context, value); @@ -37,16 +37,16 @@ set(VALUE self, VALUE name, VALUE value) static VALUE /* function? */ function_p(VALUE self) { - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); return JS_TypeOfValue(proxy->context->js, proxy->value) == JSTYPE_FUNCTION; } static VALUE /* respond_to?(sym) */ respond_to_p(VALUE self, VALUE sym) { - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); char* name = rb_id2name(SYM2ID(sym)); @@ -67,11 +67,11 @@ respond_to_p(VALUE self, VALUE sym) native_call(int argc, VALUE* argv, VALUE self) /* native_call(global, *args) */ { if (!function_p(self)) - Johnson_Error_raise("This Johnson::SpiderMonkey::RubyProxy isn't a function."); + Johnson_Error_raise("This Johnson::SpiderMonkey::RubyLandProxy isn't a function."); - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); jsval global = convert_to_js(proxy->context, argv[0]); jsval args[argc - 1]; @@ -91,8 +91,8 @@ native_call(int argc, VALUE* argv, VALUE self) /* native_call(global, *args) */ static VALUE /* each(&block) */ each(VALUE self) { - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); JSObject* value = JSVAL_TO_OBJECT(proxy->value); @@ -151,8 +151,8 @@ each(VALUE self) static VALUE length(VALUE self) { - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); JSObject* value = JSVAL_TO_OBJECT(proxy->value); @@ -176,8 +176,8 @@ length(VALUE self) /* private */ static VALUE /* context */ context(VALUE self) { - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); return (VALUE)JS_GetContextPrivate(proxy->context->js); } @@ -186,8 +186,8 @@ function_property_p(VALUE self, VALUE name) { Check_Type(name, T_STRING); - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); jsval js_value; @@ -200,8 +200,8 @@ function_property_p(VALUE self, VALUE name) /* private */ static VALUE call_function_property(int argc, VALUE* argv, VALUE self) { - OurRubyProxy* proxy; - Data_Get_Struct(self, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(self, RubyLandProxy, proxy); jsval function; @@ -230,7 +230,7 @@ call_function_property(int argc, VALUE* argv, VALUE self) //// INFRASTRUCTURE BELOW HERE //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// -static void finalize(OurRubyProxy* proxy) +static void finalize(RubyLandProxy* proxy) { // could get finalized after the context has been freed if (proxy->context) @@ -255,17 +255,17 @@ JSBool ruby_value_is_proxy(VALUE maybe_proxy) return proxy_class == CLASS_OF(maybe_proxy); } -jsval unwrap_ruby_proxy(OurContext* context, VALUE wrapped) +jsval unwrap_ruby_land_proxy(OurContext* context, VALUE wrapped) { assert(ruby_value_is_proxy(wrapped)); - OurRubyProxy* proxy; - Data_Get_Struct(wrapped, OurRubyProxy, proxy); + RubyLandProxy* proxy; + Data_Get_Struct(wrapped, RubyLandProxy, proxy); return proxy->value; } -VALUE make_ruby_proxy(OurContext* context, jsval value) +VALUE make_ruby_land_proxy(OurContext* context, jsval value) { VALUE id = (VALUE)JS_HashTableLookup(context->jsids, (void *)value); @@ -278,8 +278,8 @@ VALUE make_ruby_proxy(OurContext* context, jsval value) else { // otherwise make one and cache it - OurRubyProxy* our_proxy; - VALUE proxy = Data_Make_Struct(proxy_class, OurRubyProxy, 0, finalize, our_proxy); + RubyLandProxy* our_proxy; + VALUE proxy = Data_Make_Struct(proxy_class, RubyLandProxy, 0, finalize, our_proxy); our_proxy->value = value; our_proxy->context = context; @@ -298,7 +298,7 @@ VALUE make_ruby_proxy(OurContext* context, jsval value) void init_Johnson_SpiderMonkey_Proxy(VALUE spidermonkey) { - proxy_class = rb_define_class_under(spidermonkey, "RubyProxy", rb_cObject); + proxy_class = rb_define_class_under(spidermonkey, "RubyLandProxy", rb_cObject); rb_define_method(proxy_class, "[]", get, 1); rb_define_method(proxy_class, "[]=", set, 2); diff --git a/ext/spidermonkey/ruby_land_proxy.h b/ext/spidermonkey/ruby_land_proxy.h new file mode 100644 index 0000000..fcd05fc --- /dev/null +++ b/ext/spidermonkey/ruby_land_proxy.h @@ -0,0 +1,16 @@ +#ifndef JOHNSON_SPIDERMONKEY_RUBY_LAND_PROXY_H +#define JOHNSON_SPIDERMONKEY_RUBY_LAND_PROXY_H + +#include "spidermonkey.h" +#include "context.h" + +typedef struct { + jsval value; + OurContext* context; +} RubyLandProxy; + +JSBool ruby_value_is_proxy(VALUE maybe_proxy); +jsval unwrap_ruby_land_proxy(OurContext* context, VALUE proxy); +VALUE make_ruby_land_proxy(OurContext* context, jsval value); + +#endif diff --git a/ext/spidermonkey/ruby_proxy.h b/ext/spidermonkey/ruby_proxy.h deleted file mode 100644 index 6b5e644..0000000 --- a/ext/spidermonkey/ruby_proxy.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef JOHNSON_SPIDERMONKEY_RUBY_PROXY_H -#define JOHNSON_SPIDERMONKEY_RUBY_PROXY_H - -#include "spidermonkey.h" -#include "context.h" - -typedef struct { - jsval value; - OurContext* context; -} OurRubyProxy; - -JSBool ruby_value_is_proxy(VALUE maybe_proxy); -jsval unwrap_ruby_proxy(OurContext* context, VALUE proxy); -VALUE make_ruby_proxy(OurContext* context, jsval value); - -#endif diff --git a/ext/spidermonkey/spidermonkey.c b/ext/spidermonkey/spidermonkey.c index 2d440a5..3066113 100644 --- a/ext/spidermonkey/spidermonkey.c +++ b/ext/spidermonkey/spidermonkey.c @@ -1,7 +1,7 @@ #include "spidermonkey.h" #include "context.h" #include "error.h" -#include "ruby_proxy.h" +#include "ruby_land_proxy.h" #include "immutable_node.h" void Init_spidermonkey() diff --git a/lib/johnson.rb b/lib/johnson.rb index 150508f..7ffa492 100644 --- a/lib/johnson.rb +++ b/lib/johnson.rb @@ -12,7 +12,7 @@ # the SpiderMonkey bits written in Ruby require "johnson/spidermonkey/context" -require "johnson/spidermonkey/ruby_proxy" +require "johnson/spidermonkey/ruby_land_proxy" require "johnson/spidermonkey/mutable_tree_visitor" require "johnson/spidermonkey/immutable_node" diff --git a/lib/johnson/spidermonkey/context.rb b/lib/johnson/spidermonkey/context.rb index 020cb13..ca6d4c5 100644 --- a/lib/johnson/spidermonkey/context.rb +++ b/lib/johnson/spidermonkey/context.rb @@ -17,34 +17,34 @@ def []=(key, value) protected - # called from JSFunction executor - js_proxy.c:call_proc + # called from JSFunction executor - js_land_proxy.c:call_proc def call_proc_by_oid(oid, *args) id2ref(oid).call(*args) end - # called from JSFunction executor - js_proxy.c:unwrap + # called from JSFunction executor - js_land_proxy.c:unwrap def id2ref(oid) ObjectSpace._id2ref(oid) end - # called from js_proxy.c:method_missing + # called from js_land_proxy.c:method_missing def jsend(target, symbol, args) - block = args.pop if args.last.is_a?(RubyProxy) && args.last.function? + block = args.pop if args.last.is_a?(RubyLandProxy) && args.last.function? target.__send__(symbol, *args, &block) end - # called from js_proxy.c:get + # called from js_land_proxy.c:get def autovivified(target, attribute) target.send(:__johnson_js_properties)[attribute] end - # called from js_proxy.c:get + # called from js_land_proxy.c:get def autovivified?(target, attribute) return false unless target.respond_to?(:__johnson_js_properties) target.send(:__johnson_js_properties).has_key?(attribute) end - # called from js_proxy.c:set + # called from js_land_proxy.c:set def autovivify(target, attribute, value) (class << target; self; end).instance_eval do unless target.respond_to?(:__johnson_js_properties) @@ -57,7 +57,7 @@ def autovivify(target, attribute, value) end define_method(:"#{attribute}") do |*args| js_prop = send(:__johnson_js_properties)[attribute] - if js_prop.is_a?(RubyProxy) && js_prop.function? + if js_prop.is_a?(RubyLandProxy) && js_prop.function? js_prop.call_using(self, *args) else js_prop @@ -68,12 +68,12 @@ def autovivify(target, attribute, value) target.send(:"#{attribute}=", value) end - # called from js_proxy.c:make_js_proxy + # called from js_land_proxy.c:make_js_land_proxy def add_gcthing(thing) @gcthings[thing.object_id] = thing end - # called from js_proxy.c:finalize + # called from js_land_proxy.c:finalize def remove_gcthing(thing) @gcthings.delete(thing.object_id) end diff --git a/lib/johnson/spidermonkey/ruby_proxy.rb b/lib/johnson/spidermonkey/ruby_land_proxy.rb similarity index 97% rename from lib/johnson/spidermonkey/ruby_proxy.rb rename to lib/johnson/spidermonkey/ruby_land_proxy.rb index 4e694d5..022d39d 100644 --- a/lib/johnson/spidermonkey/ruby_proxy.rb +++ b/lib/johnson/spidermonkey/ruby_land_proxy.rb @@ -1,6 +1,6 @@ module Johnson #:nodoc: module SpiderMonkey #:nodoc: - class RubyProxy # native + class RubyLandProxy # native include Enumerable def initialize diff --git a/test/johnson/spidermonkey/js_proxy_test.rb b/test/johnson/spidermonkey/js_proxy_test.rb index a2de38a..901aeaa 100644 --- a/test/johnson/spidermonkey/js_proxy_test.rb +++ b/test/johnson/spidermonkey/js_proxy_test.rb @@ -2,7 +2,7 @@ module Johnson module SpiderMonkey - class JSProxyTest < Johnson::TestCase + class JSLandProxyTest < Johnson::TestCase module AModule end diff --git a/test/johnson/spidermonkey/ruby_proxy_test.rb b/test/johnson/spidermonkey/ruby_land_proxy_test.rb similarity index 92% rename from test/johnson/spidermonkey/ruby_proxy_test.rb rename to test/johnson/spidermonkey/ruby_land_proxy_test.rb index 9d502db..af001ac 100644 --- a/test/johnson/spidermonkey/ruby_proxy_test.rb +++ b/test/johnson/spidermonkey/ruby_land_proxy_test.rb @@ -2,19 +2,19 @@ module Johnson module SpiderMonkey - class RubyProxyTest < Johnson::TestCase + class RubyLandProxyTest < Johnson::TestCase def setup @context = Johnson::SpiderMonkey::Context.new @context.evaluate(Johnson::PRELUDE) end def test_constructing_a_proxy_directly_asplodes - assert_raise(Johnson::Error) { Johnson::SpiderMonkey::RubyProxy.new } + assert_raise(Johnson::Error) { Johnson::SpiderMonkey::RubyLandProxy.new } end def test_objects_get_wrapped_as_proxies - assert_kind_of(Johnson::SpiderMonkey::RubyProxy, @context.evaluate("x = {}")) - assert_kind_of(Johnson::SpiderMonkey::RubyProxy, @context.evaluate("new Object()")) + assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, @context.evaluate("x = {}")) + assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, @context.evaluate("new Object()")) end def test_proxies_get_unwrapped_when_roundtripping @@ -25,7 +25,7 @@ def test_proxies_get_unwrapped_when_roundtripping def test_functions_get_wrapped_as_proxies f = @context.evaluate("function() {}") - assert_kind_of(Johnson::SpiderMonkey::RubyProxy, f) + assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, f) assert(f.function?) end @@ -57,7 +57,7 @@ def test_function_proxies_are_called_with_a_global_this def test_can_be_indexed_by_string proxy = @context.evaluate("x = { foo: 42 }") - assert_kind_of(Johnson::SpiderMonkey::RubyProxy, proxy) + assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, proxy) assert_equal(42, proxy["foo"])