190
191
} else if ( args[n]->result_type() == REAL_RESULT || args[n]->result_type() == DECIMAL_RESULT ) {
191
192
a->Set( n-1, v8::Number::New(args[n]->val_real() ) );
192
193
} else if ( true || args[n]->result_type() == STRING_RESULT ) {
193
// Default to creating string values in JavaScript
194
a->Set( n-1, v8::String::New(args[n]->val_str(str)->c_str() ) );
194
if ( args[n]->is_datetime() ) {
195
// DATE/TIME values are also STRING_RESULT, make them a Date type in v8
196
// Now we need to get the unix timestamp integer, surprisingly tricky...
197
// TODO: This should really be just args[n]->get_epoch_seconds(). I need to write a separate patch for Item class one of these days.
200
args[n]->get_date(ltime, 0);
201
temporal.set_years(ltime.year);
202
temporal.set_months(ltime.month);
203
temporal.set_days(ltime.day);
204
temporal.set_hours(ltime.hour);
205
temporal.set_minutes(ltime.minute);
206
temporal.set_seconds(ltime.second);
207
temporal.set_epoch_seconds();
208
if (temporal.is_valid())
211
temporal.to_time_t(tmp);
212
// Pay attention, Ecmascript defines a date as *milliseconds* since unix epoch
213
// Also, on platforms where time_t is 32 bit, we need explicit cast to 64 bit integer
214
a->Set( n-1, v8::Date::New(((uint64_t)tmp)*1000) );
216
a->Set( n-1, v8::String::New(args[n]->val_str(str)->c_str() ) );
219
// Default to creating string values in JavaScript
220
a->Set( n-1, v8::String::New(args[n]->val_str(str)->c_str() ) );
196
223
// If user has given a name to the arguments, pass these as global variables
197
224
if( ! args[n]->is_autogenerated_name ) {
198
225
if( args[n]->result_type() == INT_RESULT ){
199
226
if( args[n]->is_unsigned() ) {
200
context->Global()->Set( v8::String::New(args[n]->name ), v8::Integer::NewFromUnsigned( (uint32_t) args[n]->val_uint() ) );
227
context->Global()->Set( v8::String::New( args[n]->name ), v8::Integer::NewFromUnsigned( (uint32_t) args[n]->val_uint() ) );
202
context->Global()->Set( v8::String::New(args[n]->name ), v8::Integer::New((int32_t)args[n]->val_int() ) );
229
context->Global()->Set( v8::String::New( args[n]->name ), v8::Integer::New((int32_t)args[n]->val_int() ) );
204
231
} else if ( args[n]->result_type() == REAL_RESULT || args[n]->result_type() == DECIMAL_RESULT ) {
205
context->Global()->Set( v8::String::New(args[n]->name ), v8::Number::New(args[n]->val_real() ) );
232
context->Global()->Set( v8::String::New( args[n]->name ), v8::Number::New(args[n]->val_real() ) );
206
233
} else if ( true || args[n]->result_type() == STRING_RESULT ) {
207
context->Global()->Set( v8::String::New(args[n]->name ), v8::String::New(args[n]->val_str(str)->c_str() ) );
234
if ( args[n]->is_datetime() ) {
235
// DATE/TIME values are also STRING_RESULT, make them a Date type in v8
236
// Now we need to get the unix timestamp integer, surprisingly tricky...
237
// TODO: This should really be just args[n]->get_epoch_seconds(). I need to write a separate patch for Item class one of these days.
240
args[n]->get_date(ltime, 0);
241
temporal.set_years(ltime.year);
242
temporal.set_months(ltime.month);
243
temporal.set_days(ltime.day);
244
temporal.set_hours(ltime.hour);
245
temporal.set_minutes(ltime.minute);
246
temporal.set_seconds(ltime.second);
247
temporal.set_epoch_seconds();
248
if (temporal.is_valid())
251
temporal.to_time_t(tmp);
252
// Pay attention, Ecmascript defines a date as *milliseconds* since unix epoch
253
// Also, on platforms where time_t is 32 bit, we need explicit cast to 64 bit integer
254
context->Global()->Set( v8::String::New( args[n]->name ), v8::Date::New(((uint64_t)tmp)*1000) );
256
context->Global()->Set( v8::String::New( args[n]->name ), v8::String::New(args[n]->val_str(str)->c_str() ) );
259
context->Global()->Set( v8::String::New( args[n]->name ), v8::String::New(args[n]->val_str(str)->c_str() ) );