// Compute modified Julian day from year, month, date.
-// The missing days in 1582 are ignored for JavaScript compatibility.
function ToJulianDay(year, month, date) {
var jy = (month > 1) ? year : year - 1;
var jm = (month > 1) ? month + 2 : month + 14;
// -------------------------------------------------------------------
+// Reused output buffer.
+var parse_buffer = $Array(7);
// ECMA 262 - 15.9.4.2
function DateParse(string) {
- var arr = %DateParseString(ToString(string));
+ var arr = %DateParseString(ToString(string), parse_buffer);
if (IS_NULL(arr)) return $NaN;
var day = MakeDay(arr[0], arr[1], arr[2]);
template <typename Char>
bool DateParser::Parse(Vector<Char> str, FixedArray* out) {
- ASSERT(out->length() == OUTPUT_SIZE);
+ ASSERT(out->length() >= OUTPUT_SIZE);
InputReader<Char> in(str);
TimeZoneComposer tz;
TimeComposer time;
template <typename Char>
static bool Parse(Vector<Char> str, FixedArray* output);
- enum {YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, UTC_OFFSET, OUTPUT_SIZE};
+ enum {
+ YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, UTC_OFFSET, OUTPUT_SIZE
+ };
private:
// Range testing
static Object* Runtime_DateParseString(Arguments args) {
HandleScope scope;
- ASSERT(args.length() == 1);
-
- CONVERT_CHECKED(String, string_object, args[0]);
+ ASSERT(args.length() == 2);
- Handle<String> str(string_object);
+ CONVERT_ARG_CHECKED(String, str, 0);
FlattenString(str);
- Handle<FixedArray> output = Factory::NewFixedArray(DateParser::OUTPUT_SIZE);
+
+ CONVERT_ARG_CHECKED(JSArray, output, 1);
+ RUNTIME_ASSERT(output->HasFastElements());
+
+ AssertNoAllocation no_allocation;
+
+ FixedArray* output_array = output->elements();
+ RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE);
bool result;
- {
- AssertNoAllocation no_allocation;
- if (StringShape(*str).IsAsciiRepresentation()) {
- result = DateParser::Parse(str->ToAsciiVector(), *output);
- } else {
- ASSERT(StringShape(*str).IsTwoByteRepresentation());
- result = DateParser::Parse(str->ToUC16Vector(), *output);
- }
+ if (StringShape(*str).IsAsciiRepresentation()) {
+ result = DateParser::Parse(str->ToAsciiVector(), output_array);
+ } else {
+ ASSERT(StringShape(*str).IsTwoByteRepresentation());
+ result = DateParser::Parse(str->ToUC16Vector(), output_array);
}
+
if (result) {
- return *Factory::NewJSArrayWithElements(output);
+ return *output;
} else {
- return *Factory::null_value();
+ return Heap::null_value();
}
}
\
/* Dates */ \
F(DateCurrentTime, 0) \
- F(DateParseString, 1) \
+ F(DateParseString, 2) \
F(DateLocalTimezone, 1) \
F(DateLocalTimeOffset, 0) \
F(DateDaylightSavingsOffset, 1) \