[jsbuilt-ins] major props fix

This commit is contained in:
sulyi 2017-01-28 00:01:34 +01:00
parent 2dd9864ea2
commit a500c34cbd

View File

@ -65,25 +65,21 @@ def to_object(o):
class JSBase(object): class JSBase(object):
def __init__(self, name, own): def __init__(self, name):
self.name = name self.name = name
self.own = own
self.props = {} self.props = {}
def __str__(self): own = {}
return '[native code]'
props = {}
class JSProtoBase(JSBase): class JSProtoBase(JSBase):
def __init__(self): def __init__(self):
super(JSProtoBase, self).__init__('', self.props) super(JSProtoBase, self).__init__('')
cls = self.__class__ cls = self.__class__
while cls is not JSProtoBase: while cls is not JSProtoBase:
cls = cls.__base__ cls = cls.__base__
props = cls.props.copy() props = cls.own.copy()
props.update(self.props) props.update(self.props)
self.props = props self.props = props
self.value = {} self.value = {}
@ -155,7 +151,7 @@ class JSObjectPrototype(JSProtoBase):
def _is_property_enumerable(self, v): def _is_property_enumerable(self, v):
return 'object is property enumerable' return 'object is property enumerable'
props = { own = {
'constructor': _constructor, 'constructor': _constructor,
'toString': _to_string, 'toString': _to_string,
'toLocaleString': _to_locale_string, 'toLocaleString': _to_locale_string,
@ -169,7 +165,7 @@ class JSObjectPrototype(JSProtoBase):
class JSObject(JSBase): class JSObject(JSBase):
def __init__(self): def __init__(self):
super(JSObject, self).__init__(self.name, self.props) super(JSObject, self).__init__(self.name)
@staticmethod @staticmethod
def construct(value=None): def construct(value=None):
@ -219,7 +215,7 @@ class JSObject(JSBase):
return 'object keys' return 'object keys'
name = 'Object' name = 'Object'
props = { own = {
'length': 1, 'length': 1,
'prototype': JSObjectPrototype(), 'prototype': JSObjectPrototype(),
'getPrototypeOf': _get_prototype_of, 'getPrototypeOf': _get_prototype_of,
@ -301,7 +297,7 @@ class JSFunctionPrototype(JSObjectPrototype):
def _bind(self, this_arg, *args): def _bind(self, this_arg, *args):
return 'function bind' return 'function bind'
props = { own = {
'length': 0, 'length': 0,
'constructor': _constructor, 'constructor': _constructor,
'toString': _to_string, 'toString': _to_string,
@ -322,7 +318,7 @@ class JSFunction(JSObject):
return JSFunction.construct(*args, **kwargs) return JSFunction.construct(*args, **kwargs)
name = 'Function' name = 'Function'
props = { own = {
'length': 1, 'length': 1,
'prototype': JSFunctionPrototype(None, None, None) 'prototype': JSFunctionPrototype(None, None, None)
} }
@ -415,7 +411,7 @@ class JSArrayPrototype(JSObjectPrototype):
def _reduce_right(self, callback, init=None): def _reduce_right(self, callback, init=None):
return 'array reduce right' return 'array reduce right'
props = { own = {
'length': 0, 'length': 0,
'constructor': _constructor, 'constructor': _constructor,
'toString': _to_string, 'toString': _to_string,
@ -448,7 +444,7 @@ class JSArray(JSObject):
return 'array is array' return 'array is array'
name = 'Array' name = 'Array'
props = { own = {
'length': 1, 'length': 1,
'prototype': JSArrayPrototype(), 'prototype': JSArrayPrototype(),
'isArray': _is_array 'isArray': _is_array