[jsbuilt-ins] global object properties mock up

* refractors: to_js
This commit is contained in:
sulyi 2017-02-20 22:16:27 +01:00
parent ec79b14148
commit dbedff27fc

View File

@ -10,7 +10,7 @@ from ..compat import compat_str
from .jsgrammar import __HEXADECIMAL_RE from .jsgrammar import __HEXADECIMAL_RE
def _to_js(o, name=None): def to_js(o, name=None):
if isinstance(o, JSProtoBase): if isinstance(o, JSProtoBase):
return o return o
elif o is None: elif o is None:
@ -35,7 +35,7 @@ def _to_js(o, name=None):
def js(func): def js(func):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
return _to_js(*func(*args, **kwargs)) return to_js(*func(*args, **kwargs))
return wrapper return wrapper
@ -164,7 +164,7 @@ def to_string(o):
elif ov == 0.0: elif ov == 0.0:
return '0' return '0'
elif ov < 0: elif ov < 0:
return '-' + to_string(_to_js(-ov)) return '-' + to_string(to_js(-ov))
elif isinf(ov): elif isinf(ov):
return 'Infinity' return 'Infinity'
else: else:
@ -312,11 +312,11 @@ class JSObject(JSBase):
def call(value=None): def call(value=None):
if value is null or value is undefined or value is None: if value is null or value is undefined or value is None:
return JSObject.construct(value) return JSObject.construct(value)
return to_object(_to_js(value)) return to_object(to_js(value))
@staticmethod @staticmethod
def construct(value=None): def construct(value=None):
value = _to_js(value) value = to_js(value)
# TODO set [[Prototype]], [[Class]], [[Extensible]], internal methods # TODO set [[Prototype]], [[Class]], [[Extensible]], internal methods
if value is undefined or value is null: if value is undefined or value is null:
return JSObjectPrototype() return JSObjectPrototype()
@ -402,7 +402,7 @@ class JSFunctionPrototype(JSObjectPrototype):
self.body = '[native code]' self.body = '[native code]'
else: else:
super(JSFunctionPrototype, self).__init__() super(JSFunctionPrototype, self).__init__()
body = _to_js(body) body = to_js(body)
self.body = to_string(body) if body is not undefined or body is not null else '' self.body = to_string(body) if body is not undefined or body is not null else ''
self.f_name = name self.f_name = name
self.arguments = list(formal_args) self.arguments = list(formal_args)
@ -776,11 +776,11 @@ class JSBoolean(JSObject):
@staticmethod @staticmethod
def call(value=None): def call(value=None):
return to_boolean(_to_js(value)) return to_boolean(to_js(value))
@staticmethod @staticmethod
def construct(value=None): def construct(value=None):
return JSBooleanPrototype(to_boolean(_to_js(value))) return JSBooleanPrototype(to_boolean(to_js(value)))
name = JSBooleanPrototype.jsclass name = JSBooleanPrototype.jsclass
own = { own = {
@ -831,11 +831,11 @@ class JSNumberPrototype(JSObjectPrototype):
class JSNumber(JSObject): class JSNumber(JSObject):
@staticmethod @staticmethod
def call(value=None): def call(value=None):
return to_number(_to_js(value)) if value is not None else 0 return to_number(to_js(value)) if value is not None else 0
@staticmethod @staticmethod
def construct(value=None): def construct(value=None):
return JSNumberPrototype(to_number(_to_js(value)) if value is not None else 0) return JSNumberPrototype(to_number(to_js(value)) if value is not None else 0)
name = JSNumberPrototype.jsclass name = JSNumberPrototype.jsclass
own = { own = {
@ -848,6 +848,43 @@ class JSNumber(JSObject):
'POSITIVE_INFINITY': float('inf'), 'POSITIVE_INFINITY': float('inf'),
} }
def _eval(code):
pass
def _parse_int(string, radix):
pass
def _parse_float(string):
pass
def _is_nan(number):
pass
def _is_infinite(number):
pass
def _decode_uri(encoded_uri):
pass
def _decode_uri_component (encoded_uri_component):
pass
def _encode_uri(uri):
pass
def _encode_uri_component(uri_component):
pass
undefined = JSBase('undefined') undefined = JSBase('undefined')
null = JSBase('null') null = JSBase('null')
true = JSBooleanPrototype(True) true = JSBooleanPrototype(True)