| 270 | } |
| 271 | |
| 272 | void NumericCasts::MarkAsCharCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 273 | try { |
| 274 | auto isolate = args.GetIsolate(); |
| 275 | |
| 276 | if (args.Length() != 1) { |
| 277 | throw NativeScriptException(string("char(x) should be called with single parameter")); |
| 278 | } |
| 279 | if (!args[0]->IsString()) { |
| 280 | throw NativeScriptException(string("char(x) should be called with single parameter containing a char representation")); |
| 281 | } |
| 282 | |
| 283 | auto context = isolate->GetCurrentContext(); |
| 284 | auto value = args[0]->ToString(context).ToLocalChecked(); |
| 285 | if (value->Length() != 1) { |
| 286 | throw NativeScriptException(string("char(x) should be called with single parameter containing a single char")); |
| 287 | } |
| 288 | |
| 289 | auto cast = Object::New(isolate); |
| 290 | MarkJsObject(isolate, cast, CastType::Char, value); |
| 291 | args.GetReturnValue().Set(cast); |
| 292 | } catch (NativeScriptException& e) { |
| 293 | e.ReThrowToV8(); |
| 294 | } catch (std::exception e) { |
| 295 | stringstream ss; |
| 296 | ss << "Error: c++ exception: " << e.what() << endl; |
| 297 | NativeScriptException nsEx(ss.str()); |
| 298 | nsEx.ReThrowToV8(); |
| 299 | } catch (...) { |
| 300 | NativeScriptException nsEx(std::string("Error: c++ exception!")); |
| 301 | nsEx.ReThrowToV8(); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | void NumericCasts::MarkAsFloatCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 306 | try { |
no test coverage detected