Skip to content
Browse files

Revert "Ruby.Class.prototype, not totally robust."

This reverts commit 765121e. My changes
introduced some SM GC root leaking. We'll pull this back in shortly.
  • Loading branch information...
1 parent 7d82c26 commit c1b88ccb27f3e431e88af45bd73d9a6073e85a2a @jbarnette committed Nov 10, 2008
View
6 MANIFEST
@@ -1,4 +1,3 @@
-.autotest
CHANGELOG
MANIFEST
MINGW32.mk
@@ -55,7 +54,6 @@ lib/johnson/nodes/node.rb
lib/johnson/nodes/ternary_node.rb
lib/johnson/parser.rb
lib/johnson/parser/syntax_error.rb
-lib/johnson/prototyper.rb
lib/johnson/runtime.rb
lib/johnson/spidermonkey/context.rb
lib/johnson/spidermonkey/debugger.rb
@@ -78,7 +76,6 @@ test/helper.rb
test/johnson/browser_test.rb
test/johnson/conversions/array_test.rb
test/johnson/conversions/boolean_test.rb
-test/johnson/conversions/by_value_test.rb
test/johnson/conversions/callable_test.rb
test/johnson/conversions/file_test.rb
test/johnson/conversions/nil_test.rb
@@ -103,7 +100,6 @@ test/johnson/nodes/function_test.rb
test/johnson/nodes/if_test.rb
test/johnson/nodes/import_test.rb
test/johnson/nodes/label_test.rb
-test/johnson/nodes/let_test.rb
test/johnson/nodes/object_literal_test.rb
test/johnson/nodes/return_test.rb
test/johnson/nodes/semi_test.rb
@@ -117,7 +113,6 @@ test/johnson/nodes/void_test.rb
test/johnson/nodes/while_test.rb
test/johnson/nodes/with_test.rb
test/johnson/prelude_test.rb
-test/johnson/prototyper_test.rb
test/johnson/runtime_test.rb
test/johnson/spidermonkey/context_test.rb
test/johnson/spidermonkey/immutable_node_test.rb
@@ -284,6 +279,7 @@ vendor/spidermonkey/js.c
vendor/spidermonkey/js.mak
vendor/spidermonkey/js.mdp
vendor/spidermonkey/js.msg
+vendor/spidermonkey/js.pkg
vendor/spidermonkey/js3240.rc
vendor/spidermonkey/jsOS240.def
vendor/spidermonkey/jsapi.c
View
1 README.rdoc
@@ -28,6 +28,7 @@ We periodically update Johnson's gemspec on Github. Rather than installing the
official releases (hosted on RubyForge), you can track the development version.
Development versions will have a timestamped version number, like 1.0.0.200806232349.
+ # requires RubyGems 1.2!
[sudo] gem sources -a http://gems.github.com
[sudo] gem install jbarnette-johnson
View
5 ext/spidermonkey/context.c
@@ -121,8 +121,3 @@ VALUE Johnson_SpiderMonkey_JSLandProxy()
{
return rb_eval_string("Johnson::SpiderMonkey::JSLandProxy");
}
-
-VALUE Johnson_Prototyper()
-{
- return rb_eval_string("Johnson::Prototyper");
-}
View
1 ext/spidermonkey/context.h
@@ -15,6 +15,5 @@ typedef struct {
void init_Johnson_SpiderMonkey_Context(VALUE spidermonkey);
VALUE Johnson_SpiderMonkey_JSLandProxy();
-VALUE Johnson_Prototyper();
#endif
View
36 ext/spidermonkey/conversions.c
@@ -10,12 +10,6 @@ DEFINE_RUBY_WRAPPER(rb_funcall_0, rb_funcall, ARGLIST3(obj, sym, argc))
DECLARE_RUBY_WRAPPER(rb_funcall_2, VALUE obj; ID sym; int argc; VALUE a; VALUE b)
DEFINE_RUBY_WRAPPER(rb_funcall_2, rb_funcall, ARGLIST5(obj, sym, argc, a, b))
-static bool convert_to_js_by_value_p(VALUE obj)
-{
- ID sym = rb_intern("convert_to_js_by_value?");
- return rb_respond_to(obj, sym) && Qtrue == rb_funcall(obj, sym, 0);
-}
-
static JSBool convert_float_or_bignum_to_js(JohnsonRuntime* runtime, VALUE float_or_bignum, jsval* retval)
{
JSContext * context = johnson_get_current_context(runtime);
@@ -43,28 +37,6 @@ static JSBool convert_symbol_to_js(JohnsonRuntime* runtime, VALUE symbol, jsval*
JRETURN;
}
-static JSBool convert_array_to_js_by_value(JohnsonRuntime* runtime, VALUE array, jsval* retval)
-{
- JSContext* context = johnson_get_current_context(runtime);
-
- PREPARE_JROOTS(context, RARRAY(array)->len + 1);
-
- JSObject* converted = JS_NewArrayObject(context, RARRAY(array)->len, NULL);
- JROOT(converted);
-
- int i; for (i = 0; i < RARRAY(array)->len; ++i) {
- jsval js_value;
-
- JCHECK(convert_to_js(runtime, RARRAY(array)->ptr[i], &js_value));
- JROOT(js_value);
- JCHECK(JS_SetElement(context, converted, i, &js_value));
- }
-
- *retval = OBJECT_TO_JSVAL(converted);
-
- JRETURN;
-}
-
static JSBool convert_regexp_to_js(JohnsonRuntime* runtime, VALUE regexp, jsval* retval)
{
JSContext * context = johnson_get_current_context(runtime);
@@ -127,14 +99,8 @@ JSBool convert_to_js(JohnsonRuntime* runtime, VALUE ruby, jsval* retval)
JCHECK(convert_symbol_to_js(runtime, ruby, retval));
JRETURN;
- case T_ARRAY:
- if (convert_to_js_by_value_p(ruby))
- {
- JCHECK(convert_array_to_js_by_value(runtime, ruby, retval));
- JRETURN;
- }
-
case T_CLASS:
+ case T_ARRAY:
case T_HASH:
case T_MODULE:
case T_FILE:
View
15 ext/spidermonkey/js_land_proxy.c
@@ -105,14 +105,9 @@ static bool autovivified_p(VALUE UNUSED(ruby_context), VALUE self, char* name)
self, rb_str_new2(name)));
}
-static bool class_or_module_p(VALUE self)
-{
- return rb_obj_is_kind_of(self, rb_cModule);
-}
-
static bool const_p(VALUE self, char* name)
{
- return class_or_module_p(self)
+ return rb_obj_is_kind_of(self, rb_cModule)
&& rb_is_const_id(rb_intern(name))
&& RTEST( rb_funcall(self, rb_intern("const_defined?"), 1, ID2SYM(rb_intern(name))) );
}
@@ -234,14 +229,6 @@ static JSBool get(JSContext* js_context, JSObject* obj, jsval id, jsval* retval)
if (!strcasecmp("__iterator__", name)) {
JCHECK(evaluate_js_property_expression(runtime, "Johnson.Generator.create", retval));
}
-
- // if the Ruby object is a class or a module, special-case a property
- // for the "prototype". No, this isn't a can of worms or anything.
-
- if (class_or_module_p(self) && !strcasecmp("prototype", name)) {
- JCHECK(call_ruby_from_js(runtime, retval, Johnson_Prototyper(),
- rb_intern("for"), 1, self));
- }
// if the Ruby object has a dynamic js property with a key
// matching the property we're looking for, pull the value out of
View
16 lib/johnson.rb
@@ -45,25 +45,11 @@ def self.parse(js, *args)
Johnson::Parser.parse(js, *args)
end
+ ###
# Create a new runtime and load all +files+. Returns a new Johnson::Runtime.
-
def self.load(*files)
rt = Johnson::Runtime.new
rt.load(*files)
rt
end
-
- # Mark +obj+ for by-value conversion to JavaScript. When +obj+ crosses
- # over into JSLand, it'll be converted into a JS-native type. This
- # happens already for strings, numbers, and regular expressions.
- #
- # Only arrays are currently supported for explicit by-value conversion.
- # If you mark an array, it will be shallowly copied into a JavaScript
- # array any time it crosses over.
-
- def self.mark_for_conversion_by_value obj
- unless obj.respond_to? :convert_to_js_by_value?
- def obj.convert_to_js_by_value?; true; end
- end
- end
end
View
38 lib/johnson/prototyper.rb
@@ -1,38 +0,0 @@
-module Johnson
- class Prototyper
- attr_reader :defaults, :functions
-
- def initialize(target)
- raise "Module or class required" unless target.is_a? Module
- @target = target
- @defaults = {}
- @functions = []
- end
-
- def []=(key, value)
- if value.respond_to?(:function?) && value.function?
- @functions |= [key.to_s]
-
- @target.__send__ :define_method, key do |*args|
- value.apply(self, Johnson.mark_for_conversion_by_value(args))
- end
- else
- Johnson::Prototyper.for(@target).defaults[key] = value
-
- @target.class_eval <<-END, __FILE__, __LINE__
- attr_writer "#{key}"
-
- def #{key}
- defined?(@#{key}) ? @#{key} :
- @#{key} = Johnson::Prototyper.for(#{@target.name}).defaults["#{key}"]
- end
- END
- end
- end
-
- def self.for(target)
- (@prototypes ||= Hash.new { |h,k| h[k] = new(k) })[target]
- end
- end
-end
-
View
2 lib/johnson/spidermonkey/js_land_proxy.rb
@@ -1,5 +1,3 @@
-require "johnson/prototyper"
-
module Johnson
module SpiderMonkey
module JSLandProxy #:nodoc:
View
5 lib/johnson/spidermonkey/ruby_land_proxy.rb
@@ -1,14 +1,15 @@
module Johnson #:nodoc:
module SpiderMonkey #:nodoc:
class RubyLandProxy # native
+ include Enumerable
+
def initialize
raise Johnson::Error, "#{self.class.name} is an internal support class."
end
private :initialize
# FIXME: need to revisit array vs non-array proxy, to_a/to_ary semantics, etc.
- include Enumerable
alias_method :size, :length
alias_method :to_ary, :to_a
@@ -43,7 +44,7 @@ def method_missing(sym, *args, &block)
# arity 1 and quacking like an assignment, treat it as a set
return self[name[0..-2]] = args[0] if assignment && 1 == args.size
- end
+ end
# okay, must really be a function
call_function_property(name, *args)
View
19 test/johnson/conversions/by_value_test.rb
@@ -1,19 +0,0 @@
-require File.expand_path(File.join(File.dirname(__FILE__), "/../../helper"))
-
-module Johnson
- module Conversions
- class ByValueTest < Johnson::TestCase
- def test_array_conversion_by_value
- beatles = %w(john paul george ringo)
- Johnson.mark_for_conversion_by_value(beatles)
-
- @runtime[:beatles] = beatles
- munged = @runtime.evaluate("beatles")
-
- assert_not_same(beatles, munged)
- assert_equal(beatles.size, munged.size)
- assert_equal(beatles[0], munged[0])
- end
- end
- end
-end
View
65 test/johnson/prototyper_test.rb
@@ -1,65 +0,0 @@
-require File.expand_path(File.join(File.dirname(__FILE__), "/../helper"))
-
-module Johnson
- class PrototyperTest < Johnson::TestCase
- def test_prototype_for_ruby_class_is_empty_by_default
- assert_kind_of Johnson::Prototyper, @runtime.evaluate("Ruby.Array.prototype")
- end
-
- def test_prototype_stays_the_same
- assert_same @runtime.evaluate("Ruby.Array.prototype"),
- @runtime.evaluate("Ruby.Array.prototype")
- end
-
- def test_prototype_property_ignores_assignment
- prototype = @runtime.evaluate("Ruby.Array.prototype")
-
- @runtime.evaluate("Ruby.Array.prototype = {}")
- assert_same prototype, @runtime.evaluate("Ruby.Array.prototype")
- end
-
- def assert_instance_method klass, name
- assert klass.instance_methods.include?(name),
- "expected #{klass.inspect} to have instance method #{name.inspect}"
- end
-
- def assert_no_instance_method klass, name
- assert !klass.instance_methods.include?(name),
- "expected #{klass.inspect} not to have instance method #{name.inspect}"
- end
-
- def test_assigning_simple_value_creates_attr_accessor_with_default
- assert_no_instance_method Array, "foo"
-
- @runtime.evaluate("Ruby.Array.prototype.foo = 42")
- assert_instance_method Array, "foo"
-
- assert_equal(42, [].foo)
- end
-
- def test_assigning_function_creates_rubyland_wrapper
- assert_no_instance_method Array, "newLength"
-
- @runtime.evaluate <<-END
- Ruby.Array.prototype.newLength = function() {
- return this.length();
- }
- END
-
- assert_instance_method Array, "newLength"
-
- a = %w(one two three)
- assert_equal a.length, a.newLength
- end
-
- def test_prototyper_keeps_track_of_methods_defined_from_prototype
-
- end
-
- # def test_retrieving_prototype_function_from_instance_does_the_right_thing
- # @runtime.evaluate("Ruby.Array.prototype.foo = function() {}")
- # assert_js("(new Ruby.Array).foo === Ruby.Array.prototype.foo")
- # end
- end
-end
-
View
8 test/johnson_test.rb
@@ -13,12 +13,4 @@ def test_evaluate_uses_a_new_runtime_each_time
assert_equal(4, Johnson.evaluate("foo", :foo => 4))
assert_raise(Johnson::Error) { Johnson.evaluate("foo") }
end
-
- def test_mark_an_object_for_conversion_by_value
- a = []
- Johnson.mark_for_conversion_by_value(a)
-
- assert_respond_to(a, :convert_to_js_by_value?)
- assert(a.convert_to_js_by_value?)
- end
end

0 comments on commit c1b88cc

Please sign in to comment.
Something went wrong with that request. Please try again.