Skip to content

Commit 4fa6796

Browse files
iamstolisabdelhaira
authored andcommitted
Correction of the handling of PropertyProxy in KeyInfoNode.
(cherry picked from commit 721827b)
1 parent 4c39f23 commit 4fa6796

File tree

2 files changed

+81
-4
lines changed
  • graal-js/src
    • com.oracle.truffle.js.scriptengine.test/src/com/oracle/truffle/js/scriptengine/test
    • com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/interop

2 files changed

+81
-4
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.truffle.js.scriptengine.test;
42+
43+
import static org.junit.Assert.assertNull;
44+
45+
import javax.script.Invocable;
46+
import javax.script.ScriptEngine;
47+
import javax.script.ScriptEngineManager;
48+
import javax.script.ScriptException;
49+
50+
import org.junit.Test;
51+
52+
public class GR29073 {
53+
54+
@Test
55+
public void test() throws ScriptException {
56+
ScriptEngineManager manager = new ScriptEngineManager();
57+
ScriptEngine engine = manager.getEngineByName(TestEngine.TESTED_ENGINE_NAME);
58+
Object array = engine.eval("[]");
59+
ArrayLike arrayLike = ((Invocable) engine).getInterface(array, ArrayLike.class);
60+
assertNull(arrayLike);
61+
}
62+
63+
public interface ArrayLike {
64+
int length();
65+
}
66+
67+
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/interop/KeyInfoNode.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -48,6 +48,7 @@
4848
import com.oracle.truffle.api.object.DynamicObject;
4949
import com.oracle.truffle.api.object.DynamicObjectLibrary;
5050
import com.oracle.truffle.api.object.Property;
51+
import com.oracle.truffle.api.profiles.BranchProfile;
5152
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
5253
import com.oracle.truffle.js.nodes.access.GetPrototypeNode;
5354
import com.oracle.truffle.js.nodes.access.IsExtensibleNode;
@@ -58,6 +59,7 @@
5859
import com.oracle.truffle.js.runtime.objects.JSProperty;
5960
import com.oracle.truffle.js.runtime.objects.Null;
6061
import com.oracle.truffle.js.runtime.objects.PropertyDescriptor;
62+
import com.oracle.truffle.js.runtime.objects.PropertyProxy;
6163
import com.oracle.truffle.js.runtime.objects.Undefined;
6264

6365
/**
@@ -83,7 +85,8 @@ public abstract class KeyInfoNode extends JavaScriptBaseNode {
8385
static boolean cachedOwnProperty(DynamicObject target, String key, int query,
8486
@CachedLibrary("target") DynamicObjectLibrary objectLibrary,
8587
@Bind("objectLibrary.getProperty(target, key)") Property property,
86-
@Cached IsCallableNode isCallable) {
88+
@Cached IsCallableNode isCallable,
89+
@Cached BranchProfile proxyBranch) {
8790
if (JSProperty.isAccessor(property)) {
8891
Accessor accessor = (Accessor) objectLibrary.getOrDefault(target, key, null);
8992
if ((query & READABLE) != 0 && accessor.hasGetter()) {
@@ -110,8 +113,15 @@ static boolean cachedOwnProperty(DynamicObject target, String key, int query,
110113
if ((query & MODIFIABLE) != 0 && JSProperty.isWritable(property)) {
111114
return true;
112115
}
113-
if ((query & INVOCABLE) != 0 && isCallable.executeBoolean(objectLibrary.getOrDefault(target, key, Undefined.instance))) {
114-
return true;
116+
if ((query & INVOCABLE) != 0) {
117+
Object value = objectLibrary.getOrDefault(target, key, Undefined.instance);
118+
if (JSProperty.isProxy(property)) {
119+
proxyBranch.enter();
120+
value = ((PropertyProxy) value).get(target);
121+
}
122+
if (isCallable.executeBoolean(value)) {
123+
return true;
124+
}
115125
}
116126
if ((query & REMOVABLE) != 0 && JSProperty.isConfigurable(property)) {
117127
return true;

0 commit comments

Comments
 (0)