Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the $262 object available within the test262 tests #1229

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions testsrc/org/mozilla/javascript/tests/Test262SuiteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
import org.mozilla.javascript.RhinoException;
import org.mozilla.javascript.Script;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.annotations.JSFunction;
import org.mozilla.javascript.annotations.JSGetter;
import org.mozilla.javascript.drivers.TestUtils;
import org.mozilla.javascript.tools.SourceReader;
import org.mozilla.javascript.tools.shell.ShellContextFactory;
Expand Down Expand Up @@ -102,7 +105,6 @@ public class Test262SuiteTest {
"class-fields-private",
"class-fields-public",
"computed-property-names",
"cross-realm",
"default-arg",
"default-parameters",
"new.target",
Expand Down Expand Up @@ -436,6 +438,52 @@ public static void tearDownClass() {
private final Test262Case testCase;
private final boolean markedAsFailing;

/** @see https://github.com/tc39/test262/blob/main/INTERPRETING.md#host-defined-functions */
public class $262 {
private ScriptableObject scope;

public $262() {}

public $262(ScriptableObject scope) {
this.scope = scope;

scope.put("$262", scope, this);
scope.setAttributes("$262", ScriptableObject.DONTENUM);
Copy link
Collaborator

@rbri rbri May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the scope setup should be done in the setup and mot in the ctor.

Copy link
Collaborator Author

@p-bakker p-bakker May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With setup you mean moving the code into the .buildScope() method?

That would entail duplicating the code between there and the $262.createRealm method, which i don't really like either

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, is see, my problem was as i saw this line

new $262(scope);

i was really confused because i did not expect that this ctor call does some kind of registration in the scope. So from the first look this line looks really useless.

Maybe a factory method that has a hint in the name about the registration?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about now?

}

@JSFunction
public void gc() {
System.gc();
}

@JSFunction
public Object evalScript(String source) {
return Context.getCurrentContext()
.evaluateString(this.scope, source, "<evalScript>", 1, null);
}

@JSGetter
public Object getGlobal() {
return this.scope;
}

@JSFunction
public $262 createRealm() {
return new $262(Context.getCurrentContext().initSafeStandardObjects());
}

@JSFunction
public void detachArrayBuffer() {
throw new UnsupportedOperationException(
"$262.detachArrayBuffer() method not yet implemented");
}

@JSGetter
public Object getAgent() {
throw new UnsupportedOperationException("$262.agent property not yet implemented");
}
}

public Test262SuiteTest(
String testFilePath,
int optLevel,
Expand All @@ -450,7 +498,8 @@ public Test262SuiteTest(
}

private Scriptable buildScope(Context cx) throws IOException {
Scriptable scope = cx.initSafeStandardObjects();
ScriptableObject scope = cx.initSafeStandardObjects();

for (String harnessFile : testCase.harnessFiles) {
if (!HARNESS_SCRIPT_CACHE.get(optLevel).containsKey(harnessFile)) {
String harnessPath = testHarnessDir + harnessFile;
Expand All @@ -462,6 +511,9 @@ private Scriptable buildScope(Context cx) throws IOException {
}
HARNESS_SCRIPT_CACHE.get(optLevel).get(harnessFile).exec(cx, scope);
}

new $262(scope);

return scope;
}

Expand Down
Loading