Skip to content

Commit 00f5260

Browse files
committed
fix getPrototypeOf behavior around foreign objects and activate tests
1 parent b5ffa7f commit 00f5260

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/interop/ForeignObjectPrototypeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ public void testPrototype() {
131131
testPrototypeIntl("Array", ProxyArray.fromArray("fun", "with", "proxy", "array"));
132132
testPrototypeIntl("Date", Instant.now());
133133
testPrototypeIntl("Map", new TestTruffleHash());
134-
// testPrototypeIntl("String", new TestTruffleString());
135-
// testPrototypeIntl("Boolean", new TestTruffleBoolean());
136-
// testPrototypeIntl("Number", new TestTruffleNumber());
134+
testPrototypeIntl("String", new TestTruffleString());
135+
testPrototypeIntl("Boolean", new TestTruffleBoolean());
136+
testPrototypeIntl("Number", new TestTruffleNumber());
137137
testPrototypeIntl("Function", (ProxyExecutable) v -> true);
138138
testPrototypeIntl("Object", new Object());
139139
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/ObjectFunctionBuiltins.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,28 @@ public ObjectGetPrototypeOfNode(JSContext context, JSBuiltin builtin) {
299299
}
300300

301301
@Specialization(guards = "!isJSObject(object)")
302-
protected JSDynamicObject getPrototypeOfNonObject(Object object) {
302+
protected JSDynamicObject getPrototypeOfNonObject(Object object,
303+
@Cached("createBinaryProfile()") ConditionProfile isForeignProfile) {
303304
if (getContext().getEcmaScriptVersion() < 6) {
304305
if (JSRuntime.isJSPrimitive(object)) {
305306
throw Errors.createTypeErrorNotAnObject(object);
306307
} else {
307308
return Null.instance;
308309
}
309310
} else {
310-
Object tobject = toObject(object);
311-
if (JSDynamicObject.isJSDynamicObject(tobject)) {
312-
return JSObject.getPrototype((JSDynamicObject) tobject);
313-
} else {
311+
if (isForeignProfile.profile(JSRuntime.isForeignObject(object))) {
312+
if (InteropLibrary.getUncached(object).isNull(object)) {
313+
throw Errors.createTypeErrorNotAnObject(object);
314+
}
314315
if (getContext().getContextOptions().hasForeignObjectPrototype()) {
315-
return getForeignObjectPrototype(tobject);
316+
return getForeignObjectPrototype(object);
316317
} else {
317318
return Null.instance;
318319
}
320+
} else {
321+
assert JSRuntime.isJSPrimitive(object);
322+
Object tobject = toObject(object);
323+
return JSObject.getPrototype((JSDynamicObject) tobject);
319324
}
320325
}
321326
}

0 commit comments

Comments
 (0)