| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, The Android Open Source Project | 2 * Copyright 2009, The Android Open Source Project |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * * Redistributions of source code must retain the above copyright | 7 * * Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * * Redistributions in binary form must reproduce the above copyright | 9 * * Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 if (!timeoutValue->IsUndefined()) { | 79 if (!timeoutValue->IsUndefined()) { |
| 80 v8::Local<v8::Number> timeoutNumber = timeoutValue->ToNumber(); | 80 v8::Local<v8::Number> timeoutNumber = timeoutValue->ToNumber(); |
| 81 if (timeoutNumber.IsEmpty()) { | 81 if (timeoutNumber.IsEmpty()) { |
| 82 succeeded = false; | 82 succeeded = false; |
| 83 return nullptr; | 83 return nullptr; |
| 84 } | 84 } |
| 85 double timeoutDouble = timeoutNumber->Value(); | 85 double timeoutDouble = timeoutNumber->Value(); |
| 86 // If the value is positive infinity, there's nothing to do. | 86 // If the value is positive infinity, there's nothing to do. |
| 87 if (!(std::isinf(timeoutDouble) && timeoutDouble > 0)) { | 87 if (!(std::isinf(timeoutDouble) && timeoutDouble > 0)) { |
| 88 v8::Local<v8::Int32> timeoutInt32 = timeoutValue->ToInt32(); | 88 unsigned timeout; |
| 89 if (timeoutInt32.IsEmpty()) { | 89 // If the value is over max of unsigned, timeout is max of unsigned. |
| 90 succeeded = false; | 90 if (timeoutDouble >= std::numeric_limits<unsigned>::max()) { |
| 91 return nullptr; | 91 timeout = std::numeric_limits<unsigned>::max(); |
| 92 } else if (timeoutDouble <= 0) { |
| 93 timeout = 0; |
| 94 } else { |
| 95 v8::Local<v8::Uint32> timeoutUint32 = timeoutValue->ToUint32(); |
| 96 if (timeoutUint32.IsEmpty()) { |
| 97 succeeded = false; |
| 98 return nullptr; |
| 99 } |
| 100 timeout = timeoutUint32->Value(); |
| 92 } | 101 } |
| 93 // Wrap to int32 and force non-negative to match behavior of window.
setTimeout. | 102 options->setTimeout(timeout); |
| 94 options->setTimeout(max(0, timeoutInt32->Value())); | |
| 95 } | 103 } |
| 96 } | 104 } |
| 97 | 105 |
| 98 v8::Local<v8::Value> maximumAgeValue = object->Get(v8AtomicString(isolate, "
maximumAge")); | 106 v8::Local<v8::Value> maximumAgeValue = object->Get(v8AtomicString(isolate, "
maximumAge")); |
| 99 if (maximumAgeValue.IsEmpty()) { | 107 if (maximumAgeValue.IsEmpty()) { |
| 100 succeeded = false; | 108 succeeded = false; |
| 101 return nullptr; | 109 return nullptr; |
| 102 } | 110 } |
| 103 if (!maximumAgeValue->IsUndefined()) { | 111 if (!maximumAgeValue->IsUndefined()) { |
| 104 v8::Local<v8::Number> maximumAgeNumber = maximumAgeValue->ToNumber(); | 112 v8::Local<v8::Number> maximumAgeNumber = maximumAgeValue->ToNumber(); |
| 105 if (maximumAgeNumber.IsEmpty()) { | 113 if (maximumAgeNumber.IsEmpty()) { |
| 106 succeeded = false; | 114 succeeded = false; |
| 107 return nullptr; | 115 return nullptr; |
| 108 } | 116 } |
| 109 double maximumAgeDouble = maximumAgeNumber->Value(); | 117 double maximumAgeDouble = maximumAgeNumber->Value(); |
| 110 if (std::isinf(maximumAgeDouble) && maximumAgeDouble > 0) { | 118 if (std::isinf(maximumAgeDouble) && maximumAgeDouble > 0) { |
| 111 // If the value is positive infinity, clear maximumAge. | 119 // If the value is positive infinity, clear maximumAge. |
| 112 options->clearMaximumAge(); | 120 options->clearMaximumAge(); |
| 113 } else { | 121 } else { |
| 114 v8::Local<v8::Int32> maximumAgeInt32 = maximumAgeValue->ToInt32(); | 122 unsigned maximumAge; |
| 115 if (maximumAgeInt32.IsEmpty()) { | 123 // If the value is over max of unsigned, maximunAge is max of unsign
ed. |
| 116 succeeded = false; | 124 if (maximumAgeDouble >= std::numeric_limits<unsigned>::max()) { |
| 117 return nullptr; | 125 maximumAge = std::numeric_limits<unsigned>::max(); |
| 126 } else if (maximumAgeDouble <= 0) { |
| 127 maximumAge = 0; |
| 128 } else { |
| 129 v8::Local<v8::Uint32> maximumAgeUint32 = maximumAgeValue->ToUint
32(); |
| 130 if (maximumAgeUint32.IsEmpty()) { |
| 131 succeeded = false; |
| 132 return nullptr; |
| 133 } |
| 134 maximumAge = maximumAgeUint32->Value(); |
| 118 } | 135 } |
| 119 // Wrap to int32 and force non-negative to match behavior of window.
setTimeout. | 136 options->setMaximumAge(maximumAge); |
| 120 options->setMaximumAge(max(0, maximumAgeInt32->Value())); | |
| 121 } | 137 } |
| 122 } | 138 } |
| 123 | 139 |
| 124 return options.release(); | 140 return options.release(); |
| 125 } | 141 } |
| 126 | 142 |
| 127 void V8Geolocation::getCurrentPositionMethodCustom(const v8::FunctionCallbackInf
o<v8::Value>& info) | 143 void V8Geolocation::getCurrentPositionMethodCustom(const v8::FunctionCallbackInf
o<v8::Value>& info) |
| 128 { | 144 { |
| 129 bool succeeded = false; | 145 bool succeeded = false; |
| 130 | 146 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 if (!succeeded) | 185 if (!succeeded) |
| 170 return; | 186 return; |
| 171 ASSERT(positionOptions); | 187 ASSERT(positionOptions); |
| 172 | 188 |
| 173 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); | 189 Geolocation* geolocation = V8Geolocation::toNative(info.Holder()); |
| 174 int watchId = geolocation->watchPosition(positionCallback.release(), positio
nErrorCallback.release(), positionOptions.release()); | 190 int watchId = geolocation->watchPosition(positionCallback.release(), positio
nErrorCallback.release(), positionOptions.release()); |
| 175 v8SetReturnValue(info, watchId); | 191 v8SetReturnValue(info, watchId); |
| 176 } | 192 } |
| 177 | 193 |
| 178 } // namespace WebCore | 194 } // namespace WebCore |
| OLD | NEW |