Skip to content

Commit 36cc2ef

Browse files
committed
[GR-36530] Backport: Do not attempt to write a regular member when the writing of a hash entry succeeded.
PullRequest: js/2358
2 parents 9727a86 + f6baf47 commit 36cc2ef

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
// Tests writing of hash/map entries. It used to throw TypeError
9+
// in strict mode, see https://github.com/oracle/graaljs/issues/522
10+
11+
load('assert.js');
12+
13+
assertSame(42, (function() {
14+
var map = new java.util.HashMap();
15+
map.x = 42;
16+
return map.x;
17+
})());
18+
19+
assertSame(43, (function() {
20+
var map = new java.util.HashMap();
21+
map['x'] = 43;
22+
return map['x'];
23+
})());
24+
25+
assertSame(44, (function() {
26+
"use strict";
27+
var map = new java.util.HashMap();
28+
map.x = 44;
29+
return map.x;
30+
})());
31+
32+
assertSame(45, (function() {
33+
"use strict";
34+
var map = new java.util.HashMap();
35+
map['x'] = 45;
36+
return map['x'];
37+
})());

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/PropertySetNode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,13 @@ private boolean performWriteMember(Object truffleObject, Object value, PropertyS
10971097
if (context.getContextOptions().hasForeignHashProperties() && interop.hasHashEntries(truffleObject)) {
10981098
try {
10991099
interop.writeHashEntry(truffleObject, stringKey, value);
1100+
return true;
11001101
} catch (UnknownKeyException | UnsupportedMessageException | UnsupportedTypeException e) {
11011102
if (root.isStrict) {
11021103
errorBranch.enter();
11031104
throw Errors.createTypeErrorInteropException(truffleObject, e, "writeHashEntry", this);
1105+
} else {
1106+
return false;
11041107
}
11051108
}
11061109
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/WriteElementNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,7 @@ protected void executeWithTargetAndIndexUnguarded(Object target, Object index, O
18581858
if (root.context.getContextOptions().hasForeignHashProperties() && interop.hasHashEntries(truffleObject)) {
18591859
try {
18601860
interop.writeHashEntry(truffleObject, propertyKey, exportedValue);
1861+
return;
18611862
} catch (UnknownKeyException | UnsupportedMessageException | UnsupportedTypeException e) {
18621863
if (root.isStrict) {
18631864
errorBranch.enter();

0 commit comments

Comments
 (0)