- ECMA-prescribed {DontEnum} attributes for length on empty arg list, and on

<any-function>.prototype.constructor.
- Put rarely-set default properties in prototypes.
- Improve a couple of comments.
This commit is contained in:
brendan%mozilla.org 2004-02-03 23:58:03 +00:00
Родитель 9b4597503c
Коммит 6dcc130f14
2 изменённых файлов: 15 добавлений и 6 удалений

Просмотреть файл

@ -39,8 +39,8 @@
*
* Execution of parse trees.
*
* XXX Standard classes are bootlegged from the host JS environment. Until
* Array and String are metacircular,
* XXX Standard classes except for eval and Function are bootlegged from the
* host JS environment. Until Array and String are metacircular,
* load('js.js');
* evaluate(snarf('js.js'));
* will fail due to pigeon-hole problems in standard class prototypes.
@ -617,7 +617,12 @@ function execute(n, x) {
case NEW_WITH_ARGS:
r = execute(n[0], x);
f = getValue(r);
a = (n.type == NEW) ? {length: 0} : execute(n[1], x);
if (n.type == NEW) {
a = {};
a.__defineProperty__('length', 0, false, false, true);
} else {
a = execute(n[1], x);
}
if (isPrimitive(f) || typeof f.__construct__ != "function")
throw new TypeError(r + " is not a constructor");
v = f.__construct__(a, x);
@ -698,7 +703,9 @@ function FunctionObject(node, scope) {
this.node = node;
this.scope = scope;
this.__defineProperty__('length', node.params.length, true, true, true);
this.__defineProperty__('prototype', {constructor: this}, true);
var proto = {};
proto.__defineProperty__('constructor', this, false, false, true);
this.__defineProperty__('prototype', proto, true);
}
var FOp = FunctionObject.prototype = {

Просмотреть файл

@ -207,14 +207,14 @@ Tokenizer.prototype = {
function CompilerContext(inFunction) {
this.inFunction = inFunction;
this.inForLoopInit = false;
this.stmtStack = [];
this.funDecls = [];
this.varDecls = [];
}
var CCp = CompilerContext.prototype;
CCp.hookLevel = CCp.bracketLevel = CCp.curlyLevel = CCp.parenLevel = 0;
CCp.bracketLevel = CCp.curlyLevel = CCp.parenLevel = CCp.hookLevel = 0;
CCp.inForLoopInit = false;
function compile(s) {
var t = new Tokenizer(s);
@ -904,6 +904,8 @@ loop:
reduce();
// Handle () now, to regularize the n-ary case for n > 0.
// We must set scanOperand in case there are arguments and
// the first one is a regexp or unary+/-.
n = operators.top();
t.scanOperand = true;
if (t.match(RIGHT_PAREN)) {