Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Renaming proxies for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarnette committed Apr 15, 2008
1 parent 3245a70 commit e18f74d
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 105 deletions.
188 changes: 182 additions & 6 deletions 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions 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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ext/spidermonkey/js_function_proxy.c
Expand Up @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions ext/spidermonkey/js_proxy.c → 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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]));

Expand All @@ -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;
}

Expand All @@ -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));
Expand All @@ -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;
Expand All @@ -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));

Expand Down
13 changes: 13 additions & 0 deletions 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
13 changes: 0 additions & 13 deletions ext/spidermonkey/js_proxy.h

This file was deleted.

1 comment on commit e18f74d

@tenderlove
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woot. You are awesome john.

Please sign in to comment.