10000 Issue #1887 by rbri · Pull Request #1888 · mozilla/rhino · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
< 10000 div id="js-flash-container" class="flash-container" data-turbo-replace>

Issue #1887 #1888

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

Merged
merged 3 commits into from
May 15, 2025
Merged
Changes from all 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
160 changes: 160 additions & 0 deletions rhino/src/test/java/org/mozilla/javascript/tests/PutPropertyTest.java
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.javascript.tests;

import org.junit.Test;
import org.mozilla.javascript.testutils.Utils;

/**
* Test for setting a property defined in the prototype chain.
*
* @author Ronald Brill
*/
public class PutPropertyTest {

public void setPropKnownAtPrototypeObject() throws Exception {
final String script =
"var WithObjectPrototype = function(array) {\n"
+ " this.prop = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = WithObjectPrototype.prototype = { prop: 7 };\n"
+ "var test = new WithObjectPrototype(['abc']);\n"
+ "'' + nlp.prop + ' # ' + test.prop";

Utils.assertWithAllModes("7 # 1", script);
}

@Test
public void setPropNotKnownAtPrototypeObject() throws Exception {
final String script =
"var WithObjectPrototype = function(array) {\n"
+ " this.prop = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = WithObjectPrototype.prototype = { length: 7 };\n"
+ "var test = new WithObjectPrototype(['abc']);\n"
+ "'' + nlp.prop + ' # ' + test.prop";

Utils.assertWithAllModes("undefined # 1", script);
}

@Test
public void setLengthKnownAtPrototypeObject() throws Exception {
final String script =
"var WithObjectPrototype = function(array) {\n"
+ " this.length = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = WithObjectPrototype.prototype = { length: 7 };\n"
+ "var test = new WithObjectPrototype(['abc']);\n"
+ "'' + nlp.length + ' # ' + test.length";

Utils.assertWithAllModes("7 # 1", script);
}

@Test
public void setLengthNotKnownAtPrototypeObject() throws Exception {
final String script =
"var WithObjectPrototype = function(array) {\n"
+ " this.length = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = WithObjectPrototype.prototype = { prop: 7 };\n"
+ "var test = new WithObjectPrototype(['abc']);\n"
+ "'' + nlp.length + ' # ' + test.length";

Utils.assertWithAllModes("undefined # 1", script);
}

@Test
public void setLengthKnownAtPrototypeArray() throws Exception {
final String script =
"var WithArrayPrototype = function(array) {\n"
+ " this.length = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = WithArrayPrototype.prototype = [];\n"
+ "var test = new WithArrayPrototype(['abc']);\n"
+ "'' + nlp.length + ' # ' + test.length";

Utils.assertWithAllModes("0 # 1", script);
}

@Test
public void setPropKnownAtPrototypePrototypeObject() throws Exception {
final String script =
"var WithObjectPrototype = function(array) {\n"
+ " this.prop = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = {}.prototype = { prop: 7 };\n"
+ "var nlpp = WithObjectPrototype.prototype = nlp;\n"
+ "var test = new WithObjectPrototype(['abc']);\n"
+ "'' + nlp.prop + ' # ' + nlpp.prop + ' # ' + test.prop";

Utils.assertWithAllModes("7 # 7 # 1", script);
}

@Test
public void setPropNotKnownAtPrototypePrototypeObject() throws Exception {
final String script =
"var WithObjectPrototype = function(array) {\n"
+ " this.prop = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = {}.prototype = { length: 7 };\n"
+ "var nlpp = WithObjectPrototype.prototype = nlp;\n"
+ "var test = new WithObjectPrototype(['abc']);\n"
+ "'' + nlp.prop + ' # ' + nlpp.prop + ' # ' + test.prop";

Utils.assertWithAllModes("undefined # undefined # 1", script);
}

@Test
public void setLengthKnownAtPrototypePrototypeObject() throws Exception {
final String script =
"var WithObjectPrototype = function(array) {\n"
+ " this.length = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = {}.prototype = { length: 7 };\n"
+ "var nlpp = WithObjectPrototype.prototype = nlp;\n"
+ "var test = new WithObjectPrototype(['abc']);\n"
+ "'' + nlp.length + ' # ' + nlpp.length + ' # ' + test.length";

Utils.assertWithAllModes("7 # 7 # 1", script);
}

@Test
public void setLengthNotKnownAtPrototypePrototypeObject() throws Exception {
final String script =
"var WithObjectPrototype = function(array) {\n"
+ " this.length = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = {}.prototype = { prop: 7 };\n"
+ "var nlpp = WithObjectPrototype.prototype = nlp;\n"
+ "var test = new WithObjectPrototype(['abc']);\n"
+ "'' + nlp.length + ' # ' + nlpp.length + ' # ' + test.length";

Utils.assertWithAllModes("undefined # undefined # 1", script);
}

@Test
public void setLengthKnownAtPrototypePrototypeArray() throws Exception {
final String script =
"var WithArrayPrototype = function(array) {\n"
+ " this.length = array.length;\n"
+ " return this;\n"
+ "}\n"
+ "var nlp = {}.prototype = [];\n"
+ "var nlpp = WithArrayPrototype.prototype = nlp;\n"
+ "var test = new WithArrayPrototype(['abc']);\n"
+ "'' + nlp.length + ' # ' + nlpp.length + ' # ' + test.length";

Utils.assertWithAllModes("0 # 0 # 1", script);
}
}
Loading
0