Permalink
Browse files

No more sandboxing. Every object *is* a real object. FREEDOM

  • Loading branch information...
Josep M. Bach
Josep M. Bach committed Jan 25, 2012
1 parent 56ecf03 commit 46702c66c1f1ccd4d6515697fd8f99a839f161db
Showing with 71 additions and 40 deletions.
  1. +65 −34 lib/noscript/runtime.rb
  2. +5 −5 test/compiler_test.rb
  3. +1 −1 test/kernel/test_case_test.rb
View
@@ -101,11 +101,41 @@ def noscript_def(name, &block)
end
class Object
- # include Noscriptable
+ include Noscriptable
def noscript_send(name, *args)
__send__ "noscript:#{send}", *args
end
+ noscript_def("clone") do |*args|
+ obj = Object.new
+ obj.__noscript_prototype__ = self
+ if properties = args.first
+ properties.keys.each do |k|
+ obj.__noscript_put__(k.to_sym, properties[k])
+ end
+ end
+ obj
+ end
+
+ noscript_def("each slot") do |*args|
+ fn = args.shift
+ __noscript_slots__.to_a.each do |k, v|
+ fn.call(self, k.to_s, v)
+ end
+ end
+
+ noscript_def("puts") do |*args|
+ puts(*args)
+ end
+
+ noscript_def("put") do |k, v|
+ __noscript_put__(k, v)
+ end
+
+ noscript_def("get") do |slot|
+ __noscript_get__(slot)
+ end
+
noscript_def("ruby") do |*args|
send *args
end
@@ -124,39 +154,40 @@ class Empty
end
class Runtime
- class ObjectKind
- include Noscriptable
- noscript_def("clone") do |*args|
- obj = ObjectKind.new
- obj.__noscript_prototype__ = self
- if properties = args.first
- properties.keys.each do |k|
- obj.__noscript_put__(k.to_sym, properties[k])
- end
- end
- obj
- end
-
- noscript_def("each slot") do |*args|
- fn = args.shift
- __noscript_slots__.to_a.each do |k, v|
- fn.call(self, k.to_s, v)
- end
- end
-
- noscript_def("puts") do |*args|
- puts(*args)
- end
-
- noscript_def("put") do |k, v|
- __noscript_put__(k, v)
- end
-
- noscript_def("get") do |slot|
- __noscript_get__(slot)
- end
- end
- Object = ObjectKind.new
+ Object = ::Object.new
+ # class ObjectKind
+ # include Noscriptable
+ # noscript_def("clone") do |*args|
+ # obj = ObjectKind.new
+ # obj.__noscript_prototype__ = self
+ # if properties = args.first
+ # properties.keys.each do |k|
+ # obj.__noscript_put__(k.to_sym, properties[k])
+ # end
+ # end
+ # obj
+ # end
+
+ # noscript_def("each slot") do |*args|
+ # fn = args.shift
+ # __noscript_slots__.to_a.each do |k, v|
+ # fn.call(self, k.to_s, v)
+ # end
+ # end
+
+ # noscript_def("puts") do |*args|
+ # puts(*args)
+ # end
+
+ # noscript_def("put") do |k, v|
+ # __noscript_put__(k, v)
+ # end
+
+ # noscript_def("get") do |slot|
+ # __noscript_get__(slot)
+ # end
+ # end
+ # Object = ObjectKind.new
end
class Function
View
@@ -136,7 +136,7 @@ def test_compile_local_assign
def test_compile_object_clone
obj = compile("Object.clone()")
- assert_kind_of Runtime::ObjectKind, obj
+ assert_kind_of Object, obj
assert_equal Runtime::Object, obj.__noscript_prototype__
end
@@ -154,10 +154,10 @@ def test_compile_slot_assign
assert_equal 3, obj.__noscript_get__(:a)
end
- # def test_compile_slot_assign_on_primitives
- # obj = compile("foo = 1; foo.a = 3; foo")
- # assert_equal 3, obj.get(:a)
- # end
+ def test_compile_slot_assign_on_primitives
+ obj = compile("foo = 1; foo.a = 3; foo")
+ assert_equal 3, obj.__noscript_get__(:a)
+ end
def test_compile_if
assert_equal 1, compile("if true; 1; end")
@@ -36,7 +36,7 @@ def test_test_case
MyTestCase.run()
CODE
- expected = "\e[32m.\e[0m\e[31mF\e[0m\e[32m.\e[0m\e[32m.\e[0m\n\n\e[0m4 tests, 4 assertions, 1 failures\n * Expected false to be truthy.\n"
+ expected = "\e[32m.\e[0m\e[32m.\e[0m\e[32m.\e[0m\e[31mF\e[0m\n\n\e[0m4 tests, 4 assertions, 1 failures\n * Expected false to be truthy.\n"
assert_output expected do
compile(code)
end

0 comments on commit 46702c6

Please sign in to comment.