| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 42 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 43 v8::Local<v8::Object> object; | 43 v8::Local<v8::Object> object; |
| 44 if (!value->ToObject(context).ToLocal(&object)) | 44 if (!value->ToObject(context).ToLocal(&object)) |
| 45 return nullptr; | 45 return nullptr; |
| 46 | 46 |
| 47 v8::Local<v8::Value> xValue; | 47 v8::Local<v8::Value> xValue; |
| 48 if (!object->Get(context, v8AtomicString(isolate, "x")).ToLocal(&xValue)) | 48 if (!object->Get(context, v8AtomicString(isolate, "x")).ToLocal(&xValue)) |
| 49 return nullptr; | 49 return nullptr; |
| 50 bool canProvideX = !isUndefinedOrNull(xValue); | 50 bool canProvideX = !isUndefinedOrNull(xValue); |
| 51 double x = xValue->NumberValue(); | 51 double x; |
| 52 V8_CALL(x, xValue, NumberValue(context), return nullptr); |
| 52 | 53 |
| 53 v8::Local<v8::Value> yValue; | 54 v8::Local<v8::Value> yValue; |
| 54 if (!object->Get(context, v8AtomicString(isolate, "y")).ToLocal(&yValue)) | 55 if (!object->Get(context, v8AtomicString(isolate, "y")).ToLocal(&yValue)) |
| 55 return nullptr; | 56 return nullptr; |
| 56 bool canProvideY = !isUndefinedOrNull(yValue); | 57 bool canProvideY = !isUndefinedOrNull(yValue); |
| 57 double y = yValue->NumberValue(); | 58 double y; |
| 59 V8_CALL(y, yValue, NumberValue(context), return nullptr); |
| 58 | 60 |
| 59 v8::Local<v8::Value> zValue; | 61 v8::Local<v8::Value> zValue; |
| 60 if (!object->Get(context, v8AtomicString(isolate, "z")).ToLocal(&zValue)) | 62 if (!object->Get(context, v8AtomicString(isolate, "z")).ToLocal(&zValue)) |
| 61 return nullptr; | 63 return nullptr; |
| 62 bool canProvideZ = !isUndefinedOrNull(zValue); | 64 bool canProvideZ = !isUndefinedOrNull(zValue); |
| 63 double z = zValue->NumberValue(); | 65 double z; |
| 66 V8_CALL(z, zValue, NumberValue(context), return nullptr); |
| 64 | 67 |
| 65 if (!canProvideX && !canProvideY && !canProvideZ) | 68 if (!canProvideX && !canProvideY && !canProvideZ) |
| 66 return nullptr; | 69 return nullptr; |
| 67 | 70 |
| 68 return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y
, canProvideZ, z); | 71 return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y
, canProvideZ, z); |
| 69 } | 72 } |
| 70 | 73 |
| 71 DeviceMotionData::RotationRate* readRotationRateArgument(v8::Local<v8::Value> va
lue, v8::Isolate* isolate) | 74 DeviceMotionData::RotationRate* readRotationRateArgument(v8::Local<v8::Value> va
lue, v8::Isolate* isolate) |
| 72 { | 75 { |
| 73 if (isUndefinedOrNull(value)) | 76 if (isUndefinedOrNull(value)) |
| 74 return nullptr; | 77 return nullptr; |
| 75 | 78 |
| 76 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | 79 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 77 v8::Local<v8::Object> object; | 80 v8::Local<v8::Object> object; |
| 78 if (!value->ToObject(context).ToLocal(&object)) | 81 if (!value->ToObject(context).ToLocal(&object)) |
| 79 return nullptr; | 82 return nullptr; |
| 80 | 83 |
| 81 v8::Local<v8::Value> alphaValue; | 84 v8::Local<v8::Value> alphaValue; |
| 82 if (!object->Get(context, v8AtomicString(isolate, "alpha")).ToLocal(&alphaVa
lue)) | 85 if (!object->Get(context, v8AtomicString(isolate, "alpha")).ToLocal(&alphaVa
lue)) |
| 83 return nullptr; | 86 return nullptr; |
| 84 bool canProvideAlpha = !isUndefinedOrNull(alphaValue); | 87 bool canProvideAlpha = !isUndefinedOrNull(alphaValue); |
| 85 double alpha = alphaValue->NumberValue(); | 88 double alpha; |
| 89 V8_CALL(alpha, alphaValue, NumberValue(context), return nullptr); |
| 86 | 90 |
| 87 v8::Local<v8::Value> betaValue; | 91 v8::Local<v8::Value> betaValue; |
| 88 if (!object->Get(context, v8AtomicString(isolate, "beta")).ToLocal(&betaValu
e)) | 92 if (!object->Get(context, v8AtomicString(isolate, "beta")).ToLocal(&betaValu
e)) |
| 89 return nullptr; | 93 return nullptr; |
| 90 bool canProvideBeta = !isUndefinedOrNull(betaValue); | 94 bool canProvideBeta = !isUndefinedOrNull(betaValue); |
| 91 double beta = betaValue->NumberValue(); | 95 double beta; |
| 96 V8_CALL(beta, betaValue, NumberValue(context), return nullptr); |
| 92 | 97 |
| 93 v8::Local<v8::Value> gammaValue; | 98 v8::Local<v8::Value> gammaValue; |
| 94 if (!object->Get(context, v8AtomicString(isolate, "gamma")).ToLocal(&gammaVa
lue)) | 99 if (!object->Get(context, v8AtomicString(isolate, "gamma")).ToLocal(&gammaVa
lue)) |
| 95 return nullptr; | 100 return nullptr; |
| 96 bool canProvideGamma = !isUndefinedOrNull(gammaValue); | 101 bool canProvideGamma = !isUndefinedOrNull(gammaValue); |
| 97 double gamma = gammaValue->NumberValue(); | 102 double gamma; |
| 103 V8_CALL(gamma, gammaValue, NumberValue(context), return nullptr); |
| 98 | 104 |
| 99 if (!canProvideAlpha && !canProvideBeta && !canProvideGamma) | 105 if (!canProvideAlpha && !canProvideBeta && !canProvideGamma) |
| 100 return nullptr; | 106 return nullptr; |
| 101 | 107 |
| 102 return DeviceMotionData::RotationRate::create(canProvideAlpha, alpha, canPro
videBeta, beta, canProvideGamma, gamma); | 108 return DeviceMotionData::RotationRate::create(canProvideAlpha, alpha, canPro
videBeta, beta, canProvideGamma, gamma); |
| 103 } | 109 } |
| 104 | 110 |
| 105 } // namespace | 111 } // namespace |
| 106 | 112 |
| 107 void V8DeviceMotionEvent::initDeviceMotionEventMethodCustom(const v8::FunctionCa
llbackInfo<v8::Value>& info) | 113 void V8DeviceMotionEvent::initDeviceMotionEventMethodCustom(const v8::FunctionCa
llbackInfo<v8::Value>& info) |
| 108 { | 114 { |
| 109 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initDeviceM
otionEvent", "DeviceMotionEvent", info.Holder(), info.GetIsolate()); | 115 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initDeviceM
otionEvent", "DeviceMotionEvent", info.Holder(), info.GetIsolate()); |
| 110 DeviceMotionEvent* impl = V8DeviceMotionEvent::toImpl(info.Holder()); | 116 DeviceMotionEvent* impl = V8DeviceMotionEvent::toImpl(info.Holder()); |
| 111 v8::Isolate* isolate = info.GetIsolate(); | 117 v8::Isolate* isolate = info.GetIsolate(); |
| 112 V8StringResource<> type(info[0]); | 118 V8StringResource<> type(info[0]); |
| 113 if (!type.prepare()) | 119 if (!type.prepare()) |
| 114 return; | 120 return; |
| 115 bool bubbles = info[1]->BooleanValue(); | 121 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
| 116 bool cancelable = info[2]->BooleanValue(); | 122 bool bubbles; |
| 123 V8_CALL(bubbles, info[1], BooleanValue(context), return); |
| 124 bool cancelable; |
| 125 V8_CALL(cancelable, info[2], BooleanValue(context), return); |
| 117 DeviceMotionData::Acceleration* acceleration = readAccelerationArgument(info
[3], isolate); | 126 DeviceMotionData::Acceleration* acceleration = readAccelerationArgument(info
[3], isolate); |
| 118 DeviceMotionData::Acceleration* accelerationIncludingGravity = readAccelerat
ionArgument(info[4], isolate); | 127 DeviceMotionData::Acceleration* accelerationIncludingGravity = readAccelerat
ionArgument(info[4], isolate); |
| 119 DeviceMotionData::RotationRate* rotationRate = readRotationRateArgument(info
[5], isolate); | 128 DeviceMotionData::RotationRate* rotationRate = readRotationRateArgument(info
[5], isolate); |
| 120 bool intervalProvided = !isUndefinedOrNull(info[6]); | 129 bool intervalProvided = !isUndefinedOrNull(info[6]); |
| 121 double interval = 0; | 130 double interval = 0; |
| 122 if (intervalProvided) { | 131 if (intervalProvided) { |
| 123 interval = toRestrictedDouble(info[6], exceptionState); | 132 interval = toRestrictedDouble(info[6], exceptionState); |
| 124 if (exceptionState.throwIfNeeded()) | 133 if (exceptionState.throwIfNeeded()) |
| 125 return; | 134 return; |
| 126 } | 135 } |
| 127 DeviceMotionData* deviceMotionData = DeviceMotionData::create(acceleration,
accelerationIncludingGravity, rotationRate, intervalProvided, interval); | 136 DeviceMotionData* deviceMotionData = DeviceMotionData::create(acceleration,
accelerationIncludingGravity, rotationRate, intervalProvided, interval); |
| 128 impl->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData); | 137 impl->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData); |
| 129 } | 138 } |
| 130 | 139 |
| 131 } // namespace blink | 140 } // namespace blink |
| OLD | NEW |