V8::Object's unexpected behavior

16 views
Skip to first unread message

Philipp Pirozhkov

unread,
Jun 7, 2012, 7:08:57 PM6/7/12
to javascript-...@googlegroups.com
Hi,

Less words, more code:

Ruby:
x = {a: 3, b: 5}
x.reject do |k,v| k == :a end
=> {:b=>5}

x = context.eval("q={a: 3, b: 5};q")
=> [object Object]
x.reject do |k,v| k == 'a' end
 => [["b", 5]]

Is it as by design?
I know JS Object is unlike Ruby's Hashmap, is this array of tuples behavior better than a hashmap?

It's just gets odd when passing an array as a value from JS to Ruby:
somerubyobject.somemethod({a: [1,2,3,4], b: 'string'})

BR, Phil

Charles Lowell

unread,
Jun 8, 2012, 3:27:04 AM6/8/12
to javascript-...@googlegroups.com
On Jun 7, 2012, at 6:08 PM, Philipp Pirozhkov wrote:

Hi,

Less words, more code:

Ruby:
x = {a: 3, b: 5}
x.reject do |k,v| k == :a end
=> {:b=>5}

x = context.eval("q={a: 3, b: 5};q")
=> [object Object]
x.reject do |k,v| k == 'a' end
 => [["b", 5]]

Is it as by design?
I know JS Object is unlike Ruby's Hashmap, is this array of tuples behavior better than a hashmap?

Phil,

No, this is probably a flaw. V8::Object enumeration should work much like a simple Hash, and V8::Array like a simple Array.

Would love a PR.

cheers,
Charles



It's just gets odd when passing an array as a value from JS to Ruby:
somerubyobject.somemethod({a: [1,2,3,4], b: 'string'})

BR, Phil

Charles Lowell 
thefrontside.net | twitter: @cowboyd | github: cowboyd




Reply all
Reply to author
Forward
0 new messages