| 332 | } |
| 333 | |
| 334 | void NumericCasts::MarkAsDoubleCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 335 | try { |
| 336 | auto isolate = args.GetIsolate(); |
| 337 | |
| 338 | if (args.Length() != 1) { |
| 339 | throw NativeScriptException(string("double(x) should be called with single parameter")); |
| 340 | } |
| 341 | if (!args[0]->IsNumber()) { |
| 342 | throw NativeScriptException(string("double(x) should be called with single parameter containing a double number representation")); |
| 343 | } |
| 344 | |
| 345 | auto context = isolate->GetCurrentContext(); |
| 346 | auto value = args[0]->ToNumber(context).ToLocalChecked(); |
| 347 | auto cast = Object::New(isolate); |
| 348 | MarkJsObject(isolate, cast, CastType::Double, value); |
| 349 | args.GetReturnValue().Set(cast); |
| 350 | } catch (NativeScriptException& e) { |
| 351 | e.ReThrowToV8(); |
| 352 | } catch (std::exception e) { |
| 353 | stringstream ss; |
| 354 | ss << "Error: c++ exception: " << e.what() << endl; |
| 355 | NativeScriptException nsEx(ss.str()); |
| 356 | nsEx.ReThrowToV8(); |
| 357 | } catch (...) { |
| 358 | NativeScriptException nsEx(std::string("Error: c++ exception!")); |
| 359 | nsEx.ReThrowToV8(); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | void NumericCasts::MarkJsObject(Isolate* isolate, const Local<Object>& object, CastType castType, const Local<Value>& value) { |
| 364 | auto key = ArgConverter::ConvertToV8String(isolate, s_castMarker); |
no test coverage detected