Author: Stephan <[email protected]>
Branch:
Changeset: r170:28481509433a
Date: 2012-01-06 14:52 +0100
http://bitbucket.org/pypy/lang-js/changeset/28481509433a/
Log: re-added Date
diff --git a/js/builtins.py b/js/builtins.py
--- a/js/builtins.py
+++ b/js/builtins.py
@@ -1,5 +1,3 @@
-import time
-
from js.jsobj import w_Undefined, W_IntNumber, w_Null, W_Boolean,\
W_FloatNumber, W_String, newbool,\
isnull_or_undefined, W_Number,\
@@ -707,20 +705,22 @@
w_Math.Put('SQRT2', _w(math_builtins.SQRT2), flags = allon)
##Date
- #w_Date = W_DateObject('Date', w_FncPrototype)
- #w_DatePrototype = create_object('Object', Value=W_String(''))
- #w_DatePrototype.Class = 'Date'
+ # 15.9.5
+ from js.jsobj import W_DateObject, W_DateConstructor
- #put_values(w_DatePrototype, {
- #'__proto__': w_DatePrototype,
- #'valueOf': get_value_of('Date')(),
- #'getTime': get_value_of('Date')()
- #})
- #_register_builtin_prototype('Date', w_DatePrototype)
+ w_DatePrototype = W_DateObject(w_NAN)
+ w_DatePrototype._prototype_ = W__Object._prototype_
- #w_Date.Put('prototype', w_DatePrototype, flags=allon)
- #w_Global.Put('Date', w_Date)
+ W_DateObject._prototype_ = w_DatePrototype
+
+ import js.builtins_date as date_builtins
+ # 15.9.5.9
+ put_native_function(w_DatePrototype, 'getTime', date_builtins.get_time)
+
+ # 15.9.3
+ w_Date = W_DateConstructor(ctx)
+ w_Global.Put('Date', w_Date)
# 15.1.1.1
w_Global.Put('NaN', w_NAN, flags = DONT_ENUM | DONT_DELETE)
diff --git a/js/builtins_date.py b/js/builtins_date.py
new file mode 100644
--- /dev/null
+++ b/js/builtins_date.py
@@ -0,0 +1,3 @@
+# 15.9.5.9
+def get_time(this, *args):
+ return this
diff --git a/js/jsobj.py b/js/jsobj.py
--- a/js/jsobj.py
+++ b/js/jsobj.py
@@ -362,6 +362,9 @@
length = len(self._primitive_value_.ToString())
self._set_property('length', _w(length), DONT_ENUM | DONT_DELETE |
READ_ONLY )
+class W_DateObject(W__PrimitiveObject):
+ _class_ = 'Date'
+
class W__Object(W_BasicObject):
def ToString(self):
try:
@@ -496,6 +499,17 @@
def Construct(self, args=[]):
return self.Call(args).ToObject()
+# 15.9.2
+class W_DateConstructor(W_BasicFunction):
+ def Call(self, args=[], this=None):
+ import time
+ return W_DateObject(int(time.time()*1000))
+
+ # 15.7.2.1
+ def Construct(self, args=[]):
+ return self.Call(args).ToObject()
+
+
class W__Function(W_BasicFunction):
_immutable_fields_ = ['_function_']
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit