Skip to content

Commit

Permalink
Fix hasOwnProperty on NativeJavaObject
Browse files Browse the repository at this point in the history
This failed since mozilla#1157 with "TypeError: Expected argument of type
object, but instead had type object"
  • Loading branch information
Schmidor committed Aug 17, 2022
1 parent 0497ce6 commit 30c5292
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum INTEGRITY_LEVEL {
* @see <a href="https://262.ecma-international.org/12.0/#sec-hasownproperty"></a>
*/
static boolean hasOwnProperty(Context cx, Object o, Object property) {
ScriptableObject obj = ScriptableObject.ensureScriptableObject(o);
Scriptable obj = ScriptableObject.ensureScriptableObject(o);
boolean result;
if (property instanceof Symbol) {
result = ScriptableObject.ensureSymbolScriptable(o).has((Symbol) property, obj);
Expand Down
21 changes: 21 additions & 0 deletions testsrc/org/mozilla/javascript/tests/NativeObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

package org.mozilla.javascript.tests;

import static org.junit.Assert.assertTrue;

import org.junit.Assert;
import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class NativeObjectTest {

Expand Down Expand Up @@ -83,4 +86,22 @@ public void getOwnPropertyDescriptorAttributes_captureStackTrace() throws Except
Assert.assertEquals("true true false", result);
Context.exit();
}

public static class JavaObj{
public String name = "test";
}

@Test
public void testNativeJavaObject_hasOwnProperty() {
Context cx = Context.enter();
try {
Scriptable scope = cx.initStandardObjects();
ScriptableObject.putProperty(scope, "javaObj", Context.javaToJS(new JavaObj(), scope));
Object result = cx.evaluateString(scope, "Object.prototype.hasOwnProperty.call(javaObj, \"name\");", "", 1,
null);
assertTrue((Boolean) result);
} finally {
Context.exit();
}
}
}

0 comments on commit 30c5292

Please sign in to comment.