Skip to content

Commit 22a103c

Browse files
committed
Binding and accessing a hash is done through $$bindkey/$$atpos.
1 parent eb81a56 commit 22a103c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/vm/js/QAST/Compiler.nqp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ class QAST::OperationsJS {
10431043

10441044
add_simple_op('knowhowattr', $T_OBJ, [], sub () {"nqp.knowhowattr"});
10451045

1046-
add_simple_op('atkey', $T_OBJ, [$T_OBJ, $T_STR], sub ($hash, $key) {"$hash[$key]"});
1046+
add_simple_op('atkey', $T_OBJ, [$T_OBJ, $T_STR], sub ($hash, $key) {"$hash.\$\$atkey($key)"});
10471047

10481048
for <savecapture usecapture> -> $op {
10491049
add_simple_op($op, $T_OBJ, [], sub () {
@@ -2158,7 +2158,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
21582158
} else {
21592159
my $hash := self.as_js($var[0], :want($T_OBJ));
21602160
my $key := self.as_js($var[1], :want($T_STR));
2161-
Chunk.new($T_OBJ, "{$hash.expr}[{$key.expr}]", [$hash, $key], :node($var));
2161+
Chunk.new($T_OBJ, "{$hash.expr}.\$\$atkey({$key.expr})", [$hash, $key], :node($var));
21622162
}
21632163
} elsif ($var.scope eq 'attribute') {
21642164
# TODO take second argument into account
@@ -2189,7 +2189,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
21892189
my $key_chunk := self.as_js($key, :want($T_STR));
21902190
my $value_chunk := self.as_js($value, :want($T_OBJ));
21912191

2192-
Chunk.new($T_OBJ, $value_chunk.expr, [$hash_chunk, $key_chunk, $value_chunk, "({$hash_chunk.expr}[{$key_chunk.expr}] = {$value_chunk.expr});\n"], :node($node));
2192+
Chunk.new($T_OBJ, $value_chunk.expr, [$hash_chunk, $key_chunk, $value_chunk, "{$hash_chunk.expr}.\$\$bindkey({$key_chunk.expr},{$value_chunk.expr});\n"], :node($node));
21932193
}
21942194

21952195
method bind_pos($array, $index, $value, :$node) {

src/vm/js/nqp-runtime/hash.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
function Hash() {
22
}
3+
Hash.prototype.$$bindkey = function(key, value) {
4+
return (this[key] = value);
5+
};
6+
Hash.prototype.$$atkey = function(key) {
7+
return this[key];
8+
};
39
module.exports = Hash;

0 commit comments

Comments
 (0)