Skip to content

Commit

Permalink
testing function length property
Browse files Browse the repository at this point in the history
git-svn-id: svn://rubyforge.org/var/svn/rkelly/trunk@158 bf63cea8-67a3-4864-ab90-c58634fce689
  • Loading branch information
aaronp committed Jan 21, 2008
1 parent ca71b80 commit 61fa914
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/rkelly/js/function.rb
Expand Up @@ -6,9 +6,9 @@ def create(*args)
if args.length > 0
parser = RKelly::Parser.new
body = args.pop
arguments = args.map { |x| RKelly::Nodes::ParameterNode.new(x) }
body = RKelly::Nodes::FunctionBodyNode.new(parser.parse(body))
self.new(body, arguments)
tree = parser.parse("function x(#{args.join(',')}) { #{body} }")
func = tree.value.first
self.new(func.function_body, func.arguments)
else
self.new
end
Expand All @@ -21,6 +21,7 @@ def initialize(body = nil, arguments = [])
@body = body
@arguments = arguments
self['toString'] = :undefined
self['length'] = arguments.length
end

def js_call(scope_chain, *params)
Expand Down
7 changes: 5 additions & 2 deletions test/function/test_15_3_1_1-1.rb
Expand Up @@ -4,8 +4,7 @@ class Expressions_15_3_1_1_1_Test < ECMAScriptTestCase
def setup
super
@runtime.execute(<<END
var MyObject = Function( "value", "this.value = value; this.valueOf = Funct
ion( 'return this.value' ); this.toString = Function( 'return String(this.value
var MyObject = Function( "value", "this.value = value; this.valueOf = Function( 'return this.value' ); this.toString = Function( 'return String(this.value
);' )" );
var myfunc = Function();
myfunc.toString = Object.prototype.toString;
Expand All @@ -17,6 +16,10 @@ def test_to_string
js_assert_equal("'[object Function]'", "myfunc.toString()")
end

def test_length
js_assert_equal("0", "myfunc.length")
end

#def test_prototype_to_string
# js_assert_equal("'[object Object]'", "myfunc.prototype.toString()")
#end
Expand Down

0 comments on commit 61fa914

Please sign in to comment.