[jsbuilt-ins] adding Number class and prototype
This commit is contained in:
parent
8729fe6e47
commit
ec79b14148
@ -776,7 +776,7 @@ class JSBoolean(JSObject):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def call(value=None):
|
def call(value=None):
|
||||||
return to_boolean(value)
|
return to_boolean(_to_js(value))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def construct(value=None):
|
def construct(value=None):
|
||||||
@ -784,19 +784,69 @@ class JSBoolean(JSObject):
|
|||||||
|
|
||||||
name = JSBooleanPrototype.jsclass
|
name = JSBooleanPrototype.jsclass
|
||||||
own = {
|
own = {
|
||||||
|
'length': 1,
|
||||||
'prototype': JSBooleanPrototype()
|
'prototype': JSBooleanPrototype()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class JSNumberPrototype(JSObjectPrototype):
|
class JSNumberPrototype(JSObjectPrototype):
|
||||||
# TODO Number object
|
|
||||||
|
@staticmethod
|
||||||
|
def _constructor(value=None):
|
||||||
|
return JSNumber.construct(value)
|
||||||
|
|
||||||
|
def _to_string(self, radix=None):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def _to_locale_string(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _value_of(self):
|
||||||
|
if jstype(self.value) is not _number_type or isinstance(self.value, JSNumberPrototype):
|
||||||
|
# TODO find way to test it in other interpreters
|
||||||
|
raise Exception('TypeError')
|
||||||
|
return self.value
|
||||||
|
|
||||||
|
def _to_fixed(self, frac_digits):
|
||||||
|
return 'Number toFixed'
|
||||||
|
|
||||||
|
def _to_exponential(self, frac_digits):
|
||||||
|
return 'Number toExponential'
|
||||||
|
|
||||||
|
def _to_precision(self, prec):
|
||||||
|
return 'Number toPrecision'
|
||||||
|
|
||||||
|
jsclass = 'Number'
|
||||||
|
own = {
|
||||||
|
'constructor': _constructor,
|
||||||
|
'toString': _to_string,
|
||||||
|
'toLocaleString': _to_locale_string,
|
||||||
|
'valueOf': _value_of,
|
||||||
|
'toFixed': _to_fixed,
|
||||||
|
'toExponential': _to_exponential,
|
||||||
|
'toPrecision': _to_precision
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class JSNumber(JSObject):
|
class JSNumber(JSObject):
|
||||||
# TODO Number class
|
@staticmethod
|
||||||
pass
|
def call(value=None):
|
||||||
|
return to_number(_to_js(value)) if value is not None else 0
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def construct(value=None):
|
||||||
|
return JSNumberPrototype(to_number(_to_js(value)) if value is not None else 0)
|
||||||
|
|
||||||
|
name = JSNumberPrototype.jsclass
|
||||||
|
own = {
|
||||||
|
'length': 1,
|
||||||
|
'prototype': JSNumberPrototype(),
|
||||||
|
'MAX_VALUE': 1.7976931348623157 * 10 ** 308,
|
||||||
|
'MIN_VALUE': 5 * 10 ** (-324),
|
||||||
|
'NAN': float('nan'),
|
||||||
|
'NEGATIVE_INFINITY': float('-inf'),
|
||||||
|
'POSITIVE_INFINITY': float('inf'),
|
||||||
|
}
|
||||||
|
|
||||||
undefined = JSBase('undefined')
|
undefined = JSBase('undefined')
|
||||||
null = JSBase('null')
|
null = JSBase('null')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user