| 303 | } |
| 304 | |
| 305 | void NumericCasts::MarkAsFloatCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 306 | try { |
| 307 | auto isolate = args.GetIsolate(); |
| 308 | |
| 309 | if (args.Length() != 1) { |
| 310 | throw NativeScriptException(string("float(x) should be called with single parameter")); |
| 311 | } |
| 312 | if (!args[0]->IsNumber()) { |
| 313 | throw NativeScriptException(string("float(x) should be called with single parameter containing a float number representation")); |
| 314 | } |
| 315 | |
| 316 | auto context = isolate->GetCurrentContext(); |
| 317 | auto value = args[0]->ToNumber(context).ToLocalChecked(); |
| 318 | auto cast = Object::New(isolate); |
| 319 | MarkJsObject(isolate, cast, CastType::Float, value); |
| 320 | args.GetReturnValue().Set(cast); |
| 321 | } catch (NativeScriptException& e) { |
| 322 | e.ReThrowToV8(); |
| 323 | } catch (std::exception e) { |
| 324 | stringstream ss; |
| 325 | ss << "Error: c++ exception: " << e.what() << endl; |
| 326 | NativeScriptException nsEx(ss.str()); |
| 327 | nsEx.ReThrowToV8(); |
| 328 | } catch (...) { |
| 329 | NativeScriptException nsEx(std::string("Error: c++ exception!")); |
| 330 | nsEx.ReThrowToV8(); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | void NumericCasts::MarkAsDoubleCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 335 | try { |
no test coverage detected