Pass tests in es5 test262 ch15.2.3.3 (except for URI-related features)

- Add every builtin function templates in es5
- Modification on Makefile target "check" should not trigger rebuild
- Add JSON object
- Implement some toString functions
- Initialize m_value properly in ObjectPropertyDescriptor constructor
This commit is contained in:
Eunji Jeong 2016-12-29 19:14:58 +09:00
commit c8840465d1
17 changed files with 670 additions and 183 deletions

View file

@ -6,6 +6,23 @@
namespace Escargot {
#define FOR_EACH_DATE_VALUES(F) \
F(Date) \
F(FullYear) \
F(Hours) \
F(Minutes) \
F(Month) \
F(UTCDate) \
F(UTCFullYear) \
F(UTCHours) \
F(UTCMinutes) \
F(UTCMonth) \
F(Milliseconds) \
F(Seconds) \
F(UTCMilliseconds) \
F(UTCSeconds)
static Value builtinDateConstructor(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
DateObject* thisObject;
@ -51,6 +68,24 @@ static Value builtinDateConstructor(ExecutionState& state, Value thisValue, size
}
}
static Value builtinDateNow(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateParse(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateUTC(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateGetTime(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getTime);
@ -79,104 +114,82 @@ static Value builtinDateToString(ExecutionState& state, Value thisValue, size_t
return thisObject->asDateObject()->toFullString(state);
}
static Value builtinDateGetDate(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
static Value builtinDateToDateString(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getDate);
if (!thisObject->isDateObject()) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().getDate.string(), errorMessage_GlobalObject_ThisNotDateObject);
}
if (!thisObject->asDateObject()->isValid())
return Value(std::numeric_limits<double>::quiet_NaN());
return Value(thisObject->asDateObject()->getDate(state));
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateGetDay(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
static Value builtinDateToTimeString(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getDay);
if (!thisObject->isDateObject()) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().getDay.string(), errorMessage_GlobalObject_ThisNotDateObject);
}
if (!thisObject->asDateObject()->isValid())
return Value(std::numeric_limits<double>::quiet_NaN());
return Value(thisObject->asDateObject()->getDay(state));
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateGetFullYear(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
static Value builtinDateToLocaleString(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getFullYear);
if (!thisObject->isDateObject()) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().getFullYear.string(), errorMessage_GlobalObject_ThisNotDateObject);
}
if (!thisObject->asDateObject()->isValid())
return Value(std::numeric_limits<double>::quiet_NaN());
return Value(thisObject->asDateObject()->getFullYear(state));
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateGetHours(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
static Value builtinDateToLocaleDateString(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getHours);
if (!thisObject->isDateObject()) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().getHours.string(), errorMessage_GlobalObject_ThisNotDateObject);
}
if (!thisObject->asDateObject()->isValid())
return Value(std::numeric_limits<double>::quiet_NaN());
return Value(thisObject->asDateObject()->getHours(state));
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateGetMilliseconds(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
static Value builtinDateToLocaleTimeString(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getMilliseconds);
if (!thisObject->isDateObject()) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().getMilliseconds.string(), errorMessage_GlobalObject_ThisNotDateObject);
}
if (!thisObject->asDateObject()->isValid())
return Value(std::numeric_limits<double>::quiet_NaN());
return Value(thisObject->asDateObject()->getMilliseconds(state));
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateGetMinutes(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
static Value builtinDateToUTCString(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getMinutes);
if (!thisObject->isDateObject()) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().getMinutes.string(), errorMessage_GlobalObject_ThisNotDateObject);
}
if (!thisObject->asDateObject()->isValid())
return Value(std::numeric_limits<double>::quiet_NaN());
return Value(thisObject->asDateObject()->getMinutes(state));
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateGetMonth(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
static Value builtinDateToISOString(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getMonth);
if (!thisObject->isDateObject()) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().getMonth.string(), errorMessage_GlobalObject_ThisNotDateObject);
}
if (!thisObject->asDateObject()->isValid())
return Value(std::numeric_limits<double>::quiet_NaN());
return Value(thisObject->asDateObject()->getMonth(state));
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateGetSeconds(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
static Value builtinDateToJSON(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getSeconds);
if (!thisObject->isDateObject()) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().getSeconds.string(), errorMessage_GlobalObject_ThisNotDateObject);
}
if (!thisObject->asDateObject()->isValid())
return Value(std::numeric_limits<double>::quiet_NaN());
return Value(thisObject->asDateObject()->getSeconds(state));
state.throwException(new ASCIIString(errorMessage_NotImplemented));
RELEASE_ASSERT_NOT_REACHED();
}
static Value builtinDateGetTimezoneOffset(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, getTimezoneOffset);
if (!thisObject->isDateObject()) {
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().getTimezoneOffset.string(), errorMessage_GlobalObject_ThisNotDateObject);
typedef int (*DateGetterInt)(ExecutionState& state);
typedef int64_t (*DateGetterInt64)(ExecutionState& state);
#define DECLARE_STATIC_DATE_GETTER(Name) \
static Value builtinDateGet##Name(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression) \
{ \
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, get##Name); \
if (!thisObject->isDateObject()) { \
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, state.context()->staticStrings().Date.string(), true, state.context()->staticStrings().get##Name.string(), errorMessage_GlobalObject_ThisNotDateObject); \
} \
if (!thisObject->asDateObject()->isValid()) \
return Value(std::numeric_limits<double>::quiet_NaN()); \
return Value(thisObject->asDateObject()->get##Name(state)); \
}
if (!thisObject->asDateObject()->isValid())
return Value(std::numeric_limits<double>::quiet_NaN());
return Value(thisObject->asDateObject()->getTimezoneOffset(state));
}
FOR_EACH_DATE_VALUES(DECLARE_STATIC_DATE_GETTER);
DECLARE_STATIC_DATE_GETTER(Day);
DECLARE_STATIC_DATE_GETTER(UTCDay);
DECLARE_STATIC_DATE_GETTER(TimezoneOffset);
#define DECLARE_STATIC_DATE_SETTER(Name) \
static Value builtinDateSet##Name(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression) \
{ \
state.throwException(new ASCIIString(errorMessage_NotImplemented)); \
RELEASE_ASSERT_NOT_REACHED(); \
}
FOR_EACH_DATE_VALUES(DECLARE_STATIC_DATE_SETTER);
static Value builtinDateSetTime(ExecutionState& state, Value thisValue, size_t argc, Value* argv, bool isNewExpression)
{
@ -207,35 +220,72 @@ void GlobalObject::installDate(ExecutionState& state)
m_datePrototype = new Object(state);
m_datePrototype->setPrototype(state, m_objectPrototype);
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().constructor), ObjectPropertyDescriptor(m_date, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_date->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().now),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().now, builtinDateNow, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_date->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().parse),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().parse, builtinDateParse, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_date->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().UTC),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().UTC, builtinDateUTC, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().getTime),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().getTime, builtinDateGetTime, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().valueOf),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().valueOf, builtinDateValueOf, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toString),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toString, builtinDateToString, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().setTime),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().setTime, builtinDateSetTime, 1, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().valueOf),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().valueOf, builtinDateValueOf, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toString),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toString, builtinDateToString, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toDateString),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toDateString, builtinDateToDateString, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toTimeString),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toTimeString, builtinDateToTimeString, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toLocaleString),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toLocaleString, builtinDateToLocaleString, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toLocaleDateString),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toLocaleDateString, builtinDateToLocaleDateString, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toLocaleTimeString),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toLocaleTimeString, builtinDateToLocaleTimeString, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toUTCString),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toUTCString, builtinDateToUTCString, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toISOString),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toISOString, builtinDateToISOString, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().toJSON),
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toJSON, builtinDateToJSON, 0, nullptr, NativeFunctionInfo::Strict)),
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
#define DATE_DEFINE_GETTER(dname) \
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().get##dname), \
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().get##dname, builtinDateGet##dname, 0, nullptr, NativeFunctionInfo::Strict)), \
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
DATE_DEFINE_GETTER(Date);
FOR_EACH_DATE_VALUES(DATE_DEFINE_GETTER);
DATE_DEFINE_GETTER(Day);
DATE_DEFINE_GETTER(FullYear);
DATE_DEFINE_GETTER(Hours);
DATE_DEFINE_GETTER(Milliseconds);
DATE_DEFINE_GETTER(Minutes);
DATE_DEFINE_GETTER(Month);
DATE_DEFINE_GETTER(Seconds);
DATE_DEFINE_GETTER(UTCDay);
DATE_DEFINE_GETTER(TimezoneOffset);
#define DATE_DEFINE_SETTER(dname) \
m_datePrototype->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().set##dname), \
ObjectPropertyDescriptor(new FunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().set##dname, builtinDateSet##dname, 1, nullptr, NativeFunctionInfo::Strict)), \
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
FOR_EACH_DATE_VALUES(DATE_DEFINE_SETTER);
m_date->setFunctionPrototype(state, m_datePrototype);