| 199 | } |
| 200 | |
| 201 | void NumericCasts::MarkAsByteCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 202 | try { |
| 203 | auto isolate = args.GetIsolate(); |
| 204 | |
| 205 | if (args.Length() != 1) { |
| 206 | throw NativeScriptException(string("byte(x) should be called with single parameter")); |
| 207 | } |
| 208 | if (!args[0]->IsString() && !args[0]->IsStringObject() && !args[0]->IsNumber() && !args[0]->IsNumberObject()) { |
| 209 | throw NativeScriptException(string("byte(x) should be called with single parameter containing a byte number representation")); |
| 210 | } |
| 211 | |
| 212 | Local<Value> value; |
| 213 | auto context = isolate->GetCurrentContext(); |
| 214 | if (args[0]->IsInt32()) { |
| 215 | value = args[0]->ToInt32(context).ToLocalChecked(); |
| 216 | } else { |
| 217 | value = args[0]->ToString(context).ToLocalChecked(); |
| 218 | } |
| 219 | |
| 220 | auto cast = Object::New(isolate); |
| 221 | MarkJsObject(isolate, cast, CastType::Byte, value); |
| 222 | args.GetReturnValue().Set(cast); |
| 223 | } catch (NativeScriptException& e) { |
| 224 | e.ReThrowToV8(); |
| 225 | } catch (std::exception e) { |
| 226 | stringstream ss; |
| 227 | ss << "Error: c++ exception: " << e.what() << endl; |
| 228 | NativeScriptException nsEx(ss.str()); |
| 229 | nsEx.ReThrowToV8(); |
| 230 | } catch (...) { |
| 231 | NativeScriptException nsEx(std::string("Error: c++ exception!")); |
| 232 | nsEx.ReThrowToV8(); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | void NumericCasts::MarkAsShortCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 237 | try { |
no test coverage detected