johnson 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/CHANGELOG.rdoc +12 -0
  2. data/Manifest.txt +6 -4
  3. data/README.rdoc +2 -8
  4. data/Rakefile +11 -11
  5. data/bin/johnson +1 -3
  6. data/ext/spidermonkey/context.c +3 -2
  7. data/ext/spidermonkey/conversions.c +61 -27
  8. data/ext/spidermonkey/conversions.h +13 -0
  9. data/ext/spidermonkey/debugger.c +13 -5
  10. data/ext/spidermonkey/debugger.h +1 -0
  11. data/ext/spidermonkey/extconf.rb +2 -3
  12. data/ext/spidermonkey/jroot.h +11 -1
  13. data/ext/spidermonkey/js_land_proxy.c +21 -11
  14. data/ext/spidermonkey/ruby_land_proxy.c +116 -41
  15. data/ext/spidermonkey/ruby_land_proxy.h +21 -0
  16. data/ext/spidermonkey/runtime.c +85 -19
  17. data/ext/spidermonkey/runtime.h +2 -0
  18. data/ext/spidermonkey/spidermonkey.c +3 -1
  19. data/lib/johnson.rb +19 -27
  20. data/lib/johnson/cli.rb +2 -1
  21. data/{js/johnson → lib/johnson/js}/cli.js +0 -0
  22. data/lib/johnson/js/core.js +34 -0
  23. data/lib/johnson/js/prelude.js +149 -0
  24. data/lib/johnson/ruby_land_proxy.rb +113 -0
  25. data/lib/johnson/runtime.rb +92 -33
  26. data/lib/johnson/spidermonkey.rb +12 -0
  27. data/lib/johnson/spidermonkey/js_land_proxy.rb +10 -8
  28. data/lib/johnson/spidermonkey/ruby_land_proxy.rb +10 -47
  29. data/lib/johnson/spidermonkey/runtime.rb +11 -31
  30. data/test/johnson/conversions/array_test.rb +41 -3
  31. data/test/johnson/conversions/string_test.rb +12 -0
  32. data/test/johnson/custom_conversions_test.rb +50 -0
  33. data/test/johnson/prelude_test.rb +23 -0
  34. data/test/johnson/runtime_test.rb +82 -2
  35. data/test/johnson/spidermonkey/ruby_land_proxy_test.rb +17 -1
  36. data/test/johnson/spidermonkey/runtime_test.rb +24 -0
  37. data/vendor/spidermonkey/jsprf.c +2 -0
  38. metadata +22 -9
  39. data/js/johnson/prelude.js +0 -80
  40. data/lib/johnson/version.rb +0 -3
  41. data/lib/rails/init.rb +0 -37
@@ -63,7 +63,9 @@ module Johnson
63
63
  end
64
64
 
65
65
  def test_calling_non_functions_complains
66
- assert_raise(RuntimeError) { @runtime.evaluate("new Object()").call }
66
+ o = @runtime.evaluate("new Object()")
67
+ assert_equal(false, o.respond_to?(:call))
68
+ assert_raise(NoMethodError) { o.call }
67
69
  end
68
70
 
69
71
  def test_functions_can_be_called
@@ -102,6 +104,20 @@ module Johnson
102
104
  assert_equal(42, proxy["bar"])
103
105
  end
104
106
 
107
+ def test_can_be_indexed_by_symbol
108
+ proxy = @runtime.evaluate("x = { foo: 42 }")
109
+ assert_kind_of(Johnson::SpiderMonkey::RubyLandProxy, proxy)
110
+
111
+ assert_equal(42, proxy[:foo])
112
+
113
+ proxy[:foo] = 99
114
+ proxy[:bar] = 42
115
+
116
+ assert_js_equal(99, "x.foo")
117
+ assert_equal(99, proxy[:foo])
118
+ assert_equal(42, proxy[:bar])
119
+ end
120
+
105
121
  def test_multilevel_indexing_works
106
122
  proxy = @runtime.evaluate("x = { foo: { bar: 42 , baz: function() { return 42 } } }")
107
123
  assert_equal(42, proxy["foo"]["bar"])
@@ -12,6 +12,30 @@ module Johnson
12
12
  Johnson::SpiderMonkey::Runtime.new
13
13
  }
14
14
  end
15
+
16
+ def test_default_is_no_debugger
17
+ assert_equal false, @runtime.debugger?
18
+ end
19
+
20
+ def test_only_accepts_real_debugger_instance
21
+ assert_raises(TypeError) {
22
+ @runtime.debugger = 17
23
+ }
24
+ assert_raises(TypeError) {
25
+ @runtime.debugger = "Yes please!"
26
+ }
27
+ assert_raises(TypeError) {
28
+ @runtime.debugger = Object.new
29
+ }
30
+ assert_raises(TypeError) {
31
+ @runtime.debugger = @runtime
32
+ }
33
+ end
34
+
35
+ def test_reports_a_debugger_is_registered
36
+ @runtime.debugger = Johnson::SpiderMonkey::Debugger.new(nil)
37
+ assert @runtime.debugger?
38
+ end
15
39
  end
16
40
  end
17
41
  end
@@ -58,6 +58,8 @@
58
58
  */
59
59
  #ifdef HAVE_VA_COPY
60
60
  #define VARARGS_ASSIGN(foo, bar) VA_COPY(foo,bar)
61
+ #elif defined(va_copy)
62
+ #define VARARGS_ASSIGN(foo, bar) va_copy(foo,bar)
61
63
  #elif defined(HAVE_VA_LIST_AS_ARRAY)
62
64
  #define VARARGS_ASSIGN(foo, bar) foo[0] = bar[0]
63
65
  #else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: johnson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Barnette
@@ -12,18 +12,28 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-07-29 00:00:00 -07:00
15
+ date: 2010-01-25 00:00:00 -08:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
- name: rake-compiler
19
+ name: gemcutter
20
20
  type: :development
21
21
  version_requirement:
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.6.0
26
+ version: 0.2.1
27
+ version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake-compiler
30
+ type: :development
31
+ version_requirement:
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: "0.6"
27
37
  version:
28
38
  - !ruby/object:Gem::Dependency
29
39
  name: hoe
@@ -33,7 +43,7 @@ dependencies:
33
43
  requirements:
34
44
  - - ">="
35
45
  - !ruby/object:Gem::Version
36
- version: 2.3.2
46
+ version: 2.5.0
37
47
  version:
38
48
  description: |-
39
49
  Johnson wraps JavaScript in a loving Ruby embrace. It embeds the
@@ -83,12 +93,13 @@ files:
83
93
  - ext/spidermonkey/runtime.h
84
94
  - ext/spidermonkey/spidermonkey.c
85
95
  - ext/spidermonkey/spidermonkey.h
86
- - js/johnson/cli.js
87
- - js/johnson/prelude.js
88
96
  - lib/johnson.rb
89
97
  - lib/johnson/cli.rb
90
98
  - lib/johnson/cli/options.rb
91
99
  - lib/johnson/error.rb
100
+ - lib/johnson/js/cli.js
101
+ - lib/johnson/js/core.js
102
+ - lib/johnson/js/prelude.js
92
103
  - lib/johnson/nodes.rb
93
104
  - lib/johnson/nodes/binary_node.rb
94
105
  - lib/johnson/nodes/for.rb
@@ -99,7 +110,9 @@ files:
99
110
  - lib/johnson/nodes/ternary_node.rb
100
111
  - lib/johnson/parser.rb
101
112
  - lib/johnson/parser/syntax_error.rb
113
+ - lib/johnson/ruby_land_proxy.rb
102
114
  - lib/johnson/runtime.rb
115
+ - lib/johnson/spidermonkey.rb
103
116
  - lib/johnson/spidermonkey/context.rb
104
117
  - lib/johnson/spidermonkey/debugger.rb
105
118
  - lib/johnson/spidermonkey/immutable_node.rb
@@ -107,7 +120,6 @@ files:
107
120
  - lib/johnson/spidermonkey/mutable_tree_visitor.rb
108
121
  - lib/johnson/spidermonkey/ruby_land_proxy.rb
109
122
  - lib/johnson/spidermonkey/runtime.rb
110
- - lib/johnson/version.rb
111
123
  - lib/johnson/visitable.rb
112
124
  - lib/johnson/visitors.rb
113
125
  - lib/johnson/visitors/dot_visitor.rb
@@ -115,7 +127,6 @@ files:
115
127
  - lib/johnson/visitors/enumerating_visitor.rb
116
128
  - lib/johnson/visitors/sexp_visitor.rb
117
129
  - lib/johnson/visitors/visitor.rb
118
- - lib/rails/init.rb
119
130
  - test/helper.rb
120
131
  - test/johnson/browser_test.rb
121
132
  - test/johnson/conversions/array_test.rb
@@ -129,6 +140,7 @@ files:
129
140
  - test/johnson/conversions/struct_test.rb
130
141
  - test/johnson/conversions/symbol_test.rb
131
142
  - test/johnson/conversions/thread_test.rb
143
+ - test/johnson/custom_conversions_test.rb
132
144
  - test/johnson/error_test.rb
133
145
  - test/johnson/extensions_test.rb
134
146
  - test/johnson/nodes/array_literal_test.rb
@@ -458,6 +470,7 @@ test_files:
458
470
  - test/johnson/conversions/struct_test.rb
459
471
  - test/johnson/conversions/symbol_test.rb
460
472
  - test/johnson/conversions/thread_test.rb
473
+ - test/johnson/custom_conversions_test.rb
461
474
  - test/johnson/error_test.rb
462
475
  - test/johnson/extensions_test.rb
463
476
  - test/johnson/nodes/array_literal_test.rb
@@ -1,80 +0,0 @@
1
- var Johnson = {};
2
-
3
- Johnson.Symbol = function(string) {
4
- this.string = string;
5
- };
6
-
7
- Johnson.Symbol.prototype = {
8
- toString: function() {
9
- return this.string;
10
- },
11
-
12
- inspect: function() {
13
- return ":" + this.toString();
14
- }
15
- };
16
-
17
- Johnson.symbolCache = {};
18
-
19
- Johnson.symbolize = function(string) {
20
- if (!Johnson.symbolCache[string])
21
- Johnson.symbolCache[string] = new Johnson.Symbol(string);
22
-
23
- return Johnson.symbolCache[string];
24
- };
25
-
26
- Object.defineProperty(String.prototype, "toSymbol", function() {
27
- return Johnson.symbolize(this.toString());
28
- }, Object.READ_ONLY | Object.NON_DELETABLE);
29
-
30
- Johnson.Generator = function(enumerableProxy) {
31
- this.items = enumerableProxy.toArray();
32
- this.index = 0;
33
- };
34
-
35
- Johnson.Generator.prototype.hasNext = function() {
36
- var len = this.items.length;
37
- if (typeof len != 'number') len = this.items.length();
38
- return this.index < len;
39
- }
40
-
41
- Johnson.Generator.prototype.next = function() {
42
- if (this.hasNext()) {
43
- return this.items[this.index++];
44
- }
45
- throw StopIteration;
46
- }
47
-
48
- Johnson.Generator.create = function() {
49
- return new Johnson.Generator(this);
50
- }
51
-
52
- Johnson.required = {};
53
-
54
- Johnson.require = function(file) {
55
- file = Ruby.File.join(Ruby.File.dirname(file),
56
- Ruby.File.basename(file, ".js") + ".js");
57
-
58
- if(Johnson.required[file]) return false;
59
-
60
- for(var directory in Ruby["$LOAD_PATH"]) {
61
- var path = Ruby.File.join(directory, file);
62
-
63
- if(Ruby.File.send("file?", path)) {
64
- Johnson.required[file] = true;
65
- Johnson.runtime.load(path);
66
-
67
- return true;
68
- }
69
- }
70
-
71
- throw Ruby.LoadError;
72
- }
73
-
74
- this.__defineGetter__("__FILE__", function() {
75
- try { throw new Error; } catch(e) {
76
- return e.stack.split("\n")[2].split("@")[1].split(":").slice(0,-1).join(":");
77
- }
78
- })
79
-
80
- null; // no need to marshal a result
@@ -1,3 +0,0 @@
1
- module Johnson #:nodoc:
2
- VERSION = "1.1.2"
3
- end
@@ -1,37 +0,0 @@
1
- require 'johnson'
2
-
3
- class EJSHandler < ActionView::TemplateHandler
4
- class EJSProxy # :nodoc:
5
- def initialize(controller)
6
- @controller = controller
7
- end
8
-
9
- def key?(pooperty)
10
- @controller.instance_variables.include?("@#{pooperty}")
11
- end
12
-
13
- def [](pooperty)
14
- @controller.instance_variable_get("@#{pooperty}")
15
- end
16
-
17
- def []=(pooperty, value)
18
- @controller.instance_variable_set("@#{pooperty}", value)
19
- end
20
- end
21
-
22
- def initialize(view)
23
- @view = view
24
- end
25
-
26
- def render(template)
27
- ctx = Johnson::Runtime.new
28
- ctx.evaluate('Johnson.require("johnson/template");')
29
- ctx['template'] = template.source
30
- ctx['controller'] = @view.controller
31
- ctx['at'] = EJSProxy.new(@view.controller)
32
-
33
- ctx.evaluate('Johnson.templatize(template).call(at)')
34
- end
35
- end
36
-
37
- ActionView::Template.register_template_handler("ejs", EJSHandler)