| 938 | |
| 939 | double retval; |
| 940 | if (!val->NumberValue(context).To(&retval)) { |
| 941 | exceptionTracker.onError("Value could not be converted"); |
| 942 | return 0; |
| 943 | } |
| 944 | return retval; |
| 945 | } |
| 946 | |
| 947 | int32_t V8JavaScriptContext::valueToInt(const JSValue& value, JSExceptionTracker& exceptionTracker) { |
| 948 | v8::HandleScope handleScope(_isolate); |
| 949 | |
| 950 | auto val = fromValdiJSValue(_isolate, value, exceptionTracker); |
| 951 | if (!exceptionTracker) { |
| 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | if (!val->IsInt32()) { |
| 956 | exceptionTracker.onError("Value is not an int32 type and cannot be converted"); |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | return val.As<v8::Int32>()->Value(); |
| 961 | } |
| 962 | |
| 963 | Ref<RefCountable> V8JavaScriptContext::valueToWrappedObject(const JSValue& value, |
| 964 | JSExceptionTracker& exceptionTracker) { |
| 965 | v8::HandleScope handleScope(_isolate); |
| 966 | auto indirect = fromValdiJSValueToIndirect(value); |
| 967 | auto objectInfo = indirect.getWithWrapperID(_isolate); |
| 968 | auto val = v8::Local<v8::Object>::Cast(objectInfo.first); |
| 969 | |
| 970 | if (indirect.isEmpty()) { |
| 971 | exceptionTracker.onError("Provided js value is already been cleared"); |
| 972 | return Ref<RefCountable>(); |
| 973 | } else if (!val->IsObject()) { |
| 974 | exceptionTracker.onError("Provided js value is not object"); |
| 975 | return Ref<RefCountable>(); |
| 976 | } else if (objectInfo.second != kWrappedObjectID) { |
| 977 | exceptionTracker.onError("Provided js value is not a wrapped object"); |
| 978 | return Ref<RefCountable>(); |
| 979 | } |
| 980 | |
| 981 | SC_ASSERT(val->InternalFieldCount() == static_cast<int>(InternalFieldSlot::Count)); |
| 982 | auto external = v8::Local<v8::External>::Cast(val->GetInternalField(static_cast<int>(InternalFieldSlot::DataSlot))); |
| 983 | if (!external->IsExternal()) { |
| 984 | exceptionTracker.onError("Internal field value is not of type external"); |
| 985 | } |
| 986 | |
| 987 | return unsafeBridge<RefCountable>(external->Value()); |
| 988 | } |
| 989 | |
| 990 | JSTypedArray V8JavaScriptContext::valueToTypedArray(const JSValue& value, JSExceptionTracker& exceptionTracker) { |
| 991 | v8::HandleScope handleScope(_isolate); |
| 992 | |
| 993 | v8::Local<v8::Value> val = fromValdiJSValue(_isolate, value, exceptionTracker); |
| 994 | if (!val->IsTypedArray()) { |
| 995 | exceptionTracker.onError("Value is not TypedArray"); |
| 996 | return JSTypedArray(); |
no test coverage detected