Skip to content

Commit fe4e144

Browse files
author
Gregory Brail
committed
Merge branch 'bug489326-builtinObjects' of https://github.com/anba/rhino into anba-bug489326-builtinObjects-3
2 parents fda5adc + 03ec260 commit fe4e144

23 files changed

Lines changed: 965 additions & 486 deletions

src/org/mozilla/javascript/Arguments.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ public Arguments(NativeCall activation)
3434
NativeFunction f = activation.function;
3535
calleeObj = f;
3636

37-
Scriptable topLevel = getTopLevelScope(parent);
38-
constructor = getProperty(topLevel, "Object");
39-
4037
int version = f.getLanguageVersion();
4138
if (version <= Context.VERSION_1_3
4239
&& version != Context.VERSION_DEFAULT)
@@ -164,9 +161,8 @@ public void delete(int index)
164161
Id_callee = 1,
165162
Id_length = 2,
166163
Id_caller = 3,
167-
Id_constructor = 4,
168164

169-
MAX_INSTANCE_ID = Id_constructor;
165+
MAX_INSTANCE_ID = Id_caller;
170166

171167
@Override
172168
protected int getMaxInstanceId()
@@ -187,7 +183,6 @@ protected int findInstanceIdInfo(String s)
187183
else if (c=='h') { X="length";id=Id_length; }
188184
else if (c=='r') { X="caller";id=Id_caller; }
189185
}
190-
else if (s_length==11) { X="constructor";id=Id_constructor; }
191186
if (X!=null && X!=s && !X.equals(s)) id = 0;
192187
break L0;
193188
}
@@ -198,10 +193,13 @@ protected int findInstanceIdInfo(String s)
198193
int attr;
199194
switch (id) {
200195
case Id_callee:
196+
attr = calleeAttr;
197+
break;
201198
case Id_caller:
199+
attr = callerAttr;
200+
break;
202201
case Id_length:
203-
case Id_constructor:
204-
attr = DONTENUM;
202+
attr = lengthAttr;
205203
break;
206204
default: throw new IllegalStateException();
207205
}
@@ -217,7 +215,6 @@ protected String getInstanceIdName(int id)
217215
case Id_callee: return "callee";
218216
case Id_length: return "length";
219217
case Id_caller: return "caller";
220-
case Id_constructor: return "constructor";
221218
}
222219
return null;
223220
}
@@ -239,8 +236,6 @@ else if (value == null) {
239236
}
240237
return value;
241238
}
242-
case Id_constructor:
243-
return constructor;
244239
}
245240
return super.getInstanceIdValue(id);
246241
}
@@ -254,11 +249,21 @@ protected void setInstanceIdValue(int id, Object value)
254249
case Id_caller:
255250
callerObj = (value != null) ? value : UniqueTag.NULL_VALUE;
256251
return;
257-
case Id_constructor: constructor = value; return;
258252
}
259253
super.setInstanceIdValue(id, value);
260254
}
261255

256+
@Override
257+
protected void setInstanceIdAttributes(int id, int attr)
258+
{
259+
switch (id) {
260+
case Id_callee: calleeAttr = attr; return;
261+
case Id_length: lengthAttr = attr; return;
262+
case Id_caller: callerAttr = attr; return;
263+
}
264+
super.setInstanceIdAttributes(id, attr);
265+
}
266+
262267
@Override
263268
Object[] getIds(boolean getAll)
264269
{
@@ -364,7 +369,10 @@ protected void defineOwnProperty(Context cx, Object id,
364369
private Object callerObj;
365370
private Object calleeObj;
366371
private Object lengthObj;
367-
private Object constructor;
372+
373+
private int callerAttr = DONTENUM;
374+
private int calleeAttr = DONTENUM;
375+
private int lengthAttr = DONTENUM;
368376

369377
private NativeCall activation;
370378

src/org/mozilla/javascript/BaseFunction.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected int findInstanceIdInfo(String s)
131131
attr = prototypePropertyAttributes;
132132
break;
133133
case Id_arguments:
134-
attr = DONTENUM | PERMANENT;
134+
attr = argumentsAttributes;
135135
break;
136136
default: throw new IllegalStateException();
137137
}
@@ -179,7 +179,11 @@ protected void setInstanceIdValue(int id, Object value)
179179
// This should not be called since "arguments" is PERMANENT
180180
Kit.codeBug();
181181
}
182-
defaultPut("arguments", value);
182+
if (defaultHas("arguments")) {
183+
defaultPut("arguments", value);
184+
} else if ((argumentsAttributes & READONLY) == 0) {
185+
argumentsObj = value;
186+
}
183187
return;
184188
case Id_name:
185189
case Id_arity:
@@ -189,6 +193,20 @@ protected void setInstanceIdValue(int id, Object value)
189193
super.setInstanceIdValue(id, value);
190194
}
191195

196+
@Override
197+
protected void setInstanceIdAttributes(int id, int attr)
198+
{
199+
switch (id) {
200+
case Id_prototype:
201+
prototypePropertyAttributes = attr;
202+
return;
203+
case Id_arguments:
204+
argumentsAttributes = attr;
205+
return;
206+
}
207+
super.setInstanceIdAttributes(id, attr);
208+
}
209+
192210
@Override
193211
protected void fillConstructorProperties(IdFunctionObject ctor)
194212
{
@@ -206,7 +224,7 @@ protected void initPrototypeId(int id)
206224
int arity;
207225
switch (id) {
208226
case Id_constructor: arity=1; s="constructor"; break;
209-
case Id_toString: arity=1; s="toString"; break;
227+
case Id_toString: arity=0; s="toString"; break;
210228
case Id_toSource: arity=1; s="toSource"; break;
211229
case Id_apply: arity=2; s="apply"; break;
212230
case Id_call: arity=1; s="call"; break;
@@ -464,7 +482,7 @@ private Object getArguments()
464482
// <Function name>.arguments is deprecated, so we use a slow
465483
// way of getting it that doesn't add to the invocation cost.
466484
// TODO: add warning, error based on version
467-
Object value = defaultGet("arguments");
485+
Object value = defaultHas("arguments") ? defaultGet("arguments") : argumentsObj;
468486
if (value != NOT_FOUND) {
469487
// Should after changing <Function name>.arguments its
470488
// activation still be available during Function call?
@@ -580,9 +598,12 @@ protected int findPrototypeId(String s)
580598
// #/string_id_map#
581599

582600
private Object prototypeProperty;
601+
private Object argumentsObj = NOT_FOUND;
602+
583603
// For function object instances, attributes are
584604
// {configurable:false, enumerable:false};
585605
// see ECMA 15.3.5.2
586606
private int prototypePropertyAttributes = PERMANENT|DONTENUM;
607+
private int argumentsAttributes = PERMANENT|DONTENUM;
587608
}
588609

src/org/mozilla/javascript/BoundFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public BoundFunction(Context cx, Scriptable scope, Callable targetFunction, Scri
3434

3535
ScriptRuntime.setFunctionProtoAndParent(this, scope);
3636

37-
Function thrower = ScriptRuntime.typeErrorThrower();
37+
Function thrower = ScriptRuntime.typeErrorThrower(cx);
3838
NativeObject throwing = new NativeObject();
3939
throwing.put("get", throwing, thrower);
4040
throwing.put("set", throwing, thrower);

src/org/mozilla/javascript/Context.java

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import java.beans.PropertyChangeEvent;
1212
import java.beans.PropertyChangeListener;
13-
import java.io.CharArrayWriter;
1413
import java.io.IOException;
1514
import java.io.PrintWriter;
1615
import java.io.Reader;
@@ -1504,11 +1503,7 @@ public Scriptable newObject(Scriptable scope, String constructorName)
15041503
public Scriptable newObject(Scriptable scope, String constructorName,
15051504
Object[] args)
15061505
{
1507-
scope = ScriptableObject.getTopLevelScope(scope);
1508-
Function ctor = ScriptRuntime.getExistingCtor(this, scope,
1509-
constructorName);
1510-
if (args == null) { args = ScriptRuntime.emptyArgs; }
1511-
return ctor.construct(this, scope, args);
1506+
return ScriptRuntime.newObject(this, scope, constructorName, args);
15121507
}
15131508

15141509
/**
@@ -2452,39 +2447,15 @@ static String getSourcePositionFromStack(int[] linep)
24522447
* A bit of a hack, but the only way to get filename and line
24532448
* number from an enclosing frame.
24542449
*/
2455-
CharArrayWriter writer = new CharArrayWriter();
2456-
RuntimeException re = new RuntimeException();
2457-
re.printStackTrace(new PrintWriter(writer));
2458-
String s = writer.toString();
2459-
int open = -1;
2460-
int close = -1;
2461-
int colon = -1;
2462-
for (int i=0; i < s.length(); i++) {
2463-
char c = s.charAt(i);
2464-
if (c == ':')
2465-
colon = i;
2466-
else if (c == '(')
2467-
open = i;
2468-
else if (c == ')')
2469-
close = i;
2470-
else if (c == '\n' && open != -1 && close != -1 && colon != -1 &&
2471-
open < colon && colon < close)
2472-
{
2473-
String fileStr = s.substring(open + 1, colon);
2474-
if (!fileStr.endsWith(".java")) {
2475-
String lineStr = s.substring(colon + 1, close);
2476-
try {
2477-
linep[0] = Integer.parseInt(lineStr);
2478-
if (linep[0] < 0) {
2479-
linep[0] = 0;
2480-
}
2481-
return fileStr;
2482-
}
2483-
catch (NumberFormatException e) {
2484-
// fall through
2485-
}
2450+
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
2451+
for (StackTraceElement st : stackTrace) {
2452+
String file = st.getFileName();
2453+
if (!(file == null || file.endsWith(".java"))) {
2454+
int line = st.getLineNumber();
2455+
if (line >= 0) {
2456+
linep[0] = line;
2457+
return file;
24862458
}
2487-
open = close = colon = -1;
24882459
}
24892460
}
24902461

@@ -2573,6 +2544,7 @@ public void removeActivationName(String name)
25732544
boolean isContinuationsTopCall;
25742545
NativeCall currentActivationCall;
25752546
XMLLib cachedXMLLib;
2547+
BaseFunction typeErrorThrower;
25762548

25772549
// for Objects, Arrays to tag themselves as being printed out,
25782550
// so they don't print themselves out recursively.

src/org/mozilla/javascript/IdScriptableObject.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ public IdScriptableObject(Scriptable scope, Scriptable prototype)
290290
super(scope, prototype);
291291
}
292292

293+
protected final boolean defaultHas(String name)
294+
{
295+
return super.has(name, this);
296+
}
297+
293298
protected final Object defaultGet(String name)
294299
{
295300
return super.get(name, this);

0 commit comments

Comments
 (0)