| 164 | } |
| 165 | |
| 166 | void NumericCasts::MarkAsLongCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 167 | try { |
| 168 | auto isolate = args.GetIsolate(); |
| 169 | |
| 170 | if (args.Length() != 1) { |
| 171 | throw NativeScriptException(string("long(x) should be called with single parameter")); |
| 172 | } |
| 173 | if (!args[0]->IsString() && !args[0]->IsStringObject() && !args[0]->IsNumber() && !args[0]->IsNumberObject()) { |
| 174 | throw NativeScriptException(string("long(x) should be called with single parameter containing a long number representation")); |
| 175 | } |
| 176 | |
| 177 | Local<Value> value; |
| 178 | auto context = isolate->GetCurrentContext(); |
| 179 | if (args[0]->IsInt32()) { |
| 180 | value = args[0]->ToInt32(context).ToLocalChecked(); |
| 181 | } else { |
| 182 | value = args[0]->ToString(context).ToLocalChecked(); |
| 183 | } |
| 184 | |
| 185 | auto cast = Object::New(isolate); |
| 186 | MarkJsObject(isolate, cast, CastType::Long, value); |
| 187 | args.GetReturnValue().Set(cast); |
| 188 | } catch (NativeScriptException& e) { |
| 189 | e.ReThrowToV8(); |
| 190 | } catch (std::exception e) { |
| 191 | stringstream ss; |
| 192 | ss << "Error: c++ exception: " << e.what() << endl; |
| 193 | NativeScriptException nsEx(ss.str()); |
| 194 | nsEx.ReThrowToV8(); |
| 195 | } catch (...) { |
| 196 | NativeScriptException nsEx(std::string("Error: c++ exception!")); |
| 197 | nsEx.ReThrowToV8(); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | void NumericCasts::MarkAsByteCallback(const v8::FunctionCallbackInfo<Value>& args) { |
| 202 | try { |
no test coverage detected