| 234 | } |
| 235 | |
| 236 | void NumericCasts::MarkAsShortCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 237 | try { |
| 238 | auto isolate = args.GetIsolate(); |
| 239 | |
| 240 | if (args.Length() != 1) { |
| 241 | throw NativeScriptException(string("short(x) should be called with single parameter")); |
| 242 | return; |
| 243 | } |
| 244 | if (!args[0]->IsString() && !args[0]->IsStringObject() && !args[0]->IsNumber() && !args[0]->IsNumberObject()) { |
| 245 | throw NativeScriptException(string("short(x) should be called with single parameter containing a short number representation")); |
| 246 | } |
| 247 | |
| 248 | Local<Value> value; |
| 249 | auto context = isolate->GetCurrentContext(); |
| 250 | if (args[0]->IsInt32()) { |
| 251 | value = args[0]->ToInt32(context).ToLocalChecked(); |
| 252 | } else { |
| 253 | value = args[0]->ToString(context).ToLocalChecked(); |
| 254 | } |
| 255 | |
| 256 | auto cast = Object::New(isolate); |
| 257 | MarkJsObject(isolate, cast, CastType::Short, value); |
| 258 | args.GetReturnValue().Set(cast); |
| 259 | } catch (NativeScriptException& e) { |
| 260 | e.ReThrowToV8(); |
| 261 | } catch (std::exception e) { |
| 262 | stringstream ss; |
| 263 | ss << "Error: c++ exception: " << e.what() << endl; |
| 264 | NativeScriptException nsEx(ss.str()); |
| 265 | nsEx.ReThrowToV8(); |
| 266 | } catch (...) { |
| 267 | NativeScriptException nsEx(std::string("Error: c++ exception!")); |
| 268 | nsEx.ReThrowToV8(); |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | void NumericCasts::MarkAsCharCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 273 | try { |
no test coverage detected