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