[pypy-svn] r55155 - pypy/branch/js-refactoring/pypy/lang/js
santagada at codespeak.net
santagada at codespeak.net
Fri May 23 20:19:02 CEST 2008
Author: santagada
Date: Fri May 23 20:18:59 2008
New Revision: 55155
Modified:
pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
Log:
each toString function should have it's own restriction to type
Modified: pypy/branch/js-refactoring/pypy/lang/js/interpreter.py
==============================================================================
--- pypy/branch/js-refactoring/pypy/lang/js/interpreter.py (original)
+++ pypy/branch/js-refactoring/pypy/lang/js/interpreter.py Fri May 23 20:18:59 2008
@@ -316,11 +316,23 @@
class W_ValueToString(W_NewBuiltin):
"this is the toString function for objects with Value"
+ mytype = ''
def Call(self, ctx, args=[], this=None):
- if this.Value.type() != 'number':
+ if this.Value.type() != self.mytype:
raise JsTypeError('Wrong type')
return W_String(this.Value.ToString(ctx))
+
+class W_NumberValueToString(W_ValueToString):
+ mytype = 'number'
+
+class W_BooleanValueToString(W_ValueToString):
+ mytype = 'boolean'
+
+class W_StringValueToString(W_ValueToString):
+ mytype = 'string'
+
+
def get_value_of(type, ctx):
class W_ValueValueOf(W_NewBuiltin):
"this is the valueOf function for objects with Value"
@@ -457,7 +469,7 @@
put_values(w_BoolPrototype, {
'constructor': w_FncPrototype,
'__proto__': w_BoolPrototype,
- 'toString': W_ValueToString(ctx),
+ 'toString': W_BooleanValueToString(ctx),
'valueOf': get_value_of('Boolean', ctx)
})
@@ -475,7 +487,7 @@
put_values(w_NumPrototype, {
'constructor': w_Number,
'__proto__': w_empty_fun,
- 'toString': W_ValueToString(ctx),
+ 'toString': W_NumberValueToString(ctx),
'valueOf': get_value_of('Number', ctx),
})
@@ -509,7 +521,7 @@
put_values(w_StrPrototype, {
'constructor': w_FncPrototype,
'__proto__': w_StrPrototype,
- 'toString': W_ValueToString(ctx),
+ 'toString': W_StringValueToString(ctx),
'valueOf': get_value_of('String', ctx),
'charAt': W_CharAt(ctx),
'concat': W_Concat(ctx),
More information about the Pypy-commit
mailing list