Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1176)

Side by Side Diff: third_party/WebKit/Source/bindings/modules/v8/custom/V8DeviceMotionEventCustom.cpp

Issue 2284623002: Remove V8_CALL macro (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
41 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 41 v8::Local<v8::Context> context = isolate->GetCurrentContext();
42 v8::Local<v8::Object> object; 42 v8::Local<v8::Object> object;
43 if (!value->ToObject(context).ToLocal(&object)) 43 if (!value->ToObject(context).ToLocal(&object))
44 return nullptr; 44 return nullptr;
45 45
46 v8::Local<v8::Value> xValue; 46 v8::Local<v8::Value> xValue;
47 if (!object->Get(context, v8AtomicString(isolate, "x")).ToLocal(&xValue)) 47 if (!object->Get(context, v8AtomicString(isolate, "x")).ToLocal(&xValue))
48 return nullptr; 48 return nullptr;
49 bool canProvideX = !isUndefinedOrNull(xValue); 49 bool canProvideX = !isUndefinedOrNull(xValue);
50 double x; 50 double x;
51 V8_CALL(x, xValue, NumberValue(context), return nullptr); 51 if (!xValue->NumberValue(context).To(&x))
52 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; 58 double y;
58 V8_CALL(y, yValue, NumberValue(context), return nullptr); 59 if (!yValue->NumberValue(context).To(&y))
60 return nullptr;
59 61
60 v8::Local<v8::Value> zValue; 62 v8::Local<v8::Value> zValue;
61 if (!object->Get(context, v8AtomicString(isolate, "z")).ToLocal(&zValue)) 63 if (!object->Get(context, v8AtomicString(isolate, "z")).ToLocal(&zValue))
62 return nullptr; 64 return nullptr;
63 bool canProvideZ = !isUndefinedOrNull(zValue); 65 bool canProvideZ = !isUndefinedOrNull(zValue);
64 double z; 66 double z;
65 V8_CALL(z, zValue, NumberValue(context), return nullptr); 67 if (!zValue->NumberValue(context).To(&z))
68 return nullptr;
66 69
67 if (!canProvideX && !canProvideY && !canProvideZ) 70 if (!canProvideX && !canProvideY && !canProvideZ)
68 return nullptr; 71 return nullptr;
69 72
70 return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y , canProvideZ, z); 73 return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y , canProvideZ, z);
71 } 74 }
72 75
73 DeviceMotionData::RotationRate* readRotationRateArgument(v8::Local<v8::Value> va lue, v8::Isolate* isolate) 76 DeviceMotionData::RotationRate* readRotationRateArgument(v8::Local<v8::Value> va lue, v8::Isolate* isolate)
74 { 77 {
75 if (isUndefinedOrNull(value)) 78 if (isUndefinedOrNull(value))
76 return nullptr; 79 return nullptr;
77 80
78 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 81 v8::Local<v8::Context> context = isolate->GetCurrentContext();
79 v8::Local<v8::Object> object; 82 v8::Local<v8::Object> object;
80 if (!value->ToObject(context).ToLocal(&object)) 83 if (!value->ToObject(context).ToLocal(&object))
81 return nullptr; 84 return nullptr;
82 85
83 v8::Local<v8::Value> alphaValue; 86 v8::Local<v8::Value> alphaValue;
84 if (!object->Get(context, v8AtomicString(isolate, "alpha")).ToLocal(&alphaVa lue)) 87 if (!object->Get(context, v8AtomicString(isolate, "alpha")).ToLocal(&alphaVa lue))
85 return nullptr; 88 return nullptr;
86 bool canProvideAlpha = !isUndefinedOrNull(alphaValue); 89 bool canProvideAlpha = !isUndefinedOrNull(alphaValue);
87 double alpha; 90 double alpha;
88 V8_CALL(alpha, alphaValue, NumberValue(context), return nullptr); 91 if (!alphaValue->NumberValue(context).To(&alpha))
92 return nullptr;
89 93
90 v8::Local<v8::Value> betaValue; 94 v8::Local<v8::Value> betaValue;
91 if (!object->Get(context, v8AtomicString(isolate, "beta")).ToLocal(&betaValu e)) 95 if (!object->Get(context, v8AtomicString(isolate, "beta")).ToLocal(&betaValu e))
92 return nullptr; 96 return nullptr;
93 bool canProvideBeta = !isUndefinedOrNull(betaValue); 97 bool canProvideBeta = !isUndefinedOrNull(betaValue);
94 double beta; 98 double beta;
95 V8_CALL(beta, betaValue, NumberValue(context), return nullptr); 99 if (!betaValue->NumberValue(context).To(&beta))
100 return nullptr;
96 101
97 v8::Local<v8::Value> gammaValue; 102 v8::Local<v8::Value> gammaValue;
98 if (!object->Get(context, v8AtomicString(isolate, "gamma")).ToLocal(&gammaVa lue)) 103 if (!object->Get(context, v8AtomicString(isolate, "gamma")).ToLocal(&gammaVa lue))
99 return nullptr; 104 return nullptr;
100 bool canProvideGamma = !isUndefinedOrNull(gammaValue); 105 bool canProvideGamma = !isUndefinedOrNull(gammaValue);
101 double gamma; 106 double gamma;
102 V8_CALL(gamma, gammaValue, NumberValue(context), return nullptr); 107 if (!gammaValue->NumberValue(context).To(&gamma))
108 return nullptr;
103 109
104 if (!canProvideAlpha && !canProvideBeta && !canProvideGamma) 110 if (!canProvideAlpha && !canProvideBeta && !canProvideGamma)
105 return nullptr; 111 return nullptr;
106 112
107 return DeviceMotionData::RotationRate::create(canProvideAlpha, alpha, canPro videBeta, beta, canProvideGamma, gamma); 113 return DeviceMotionData::RotationRate::create(canProvideAlpha, alpha, canPro videBeta, beta, canProvideGamma, gamma);
108 } 114 }
109 115
110 } // namespace 116 } // namespace
111 117
112 void V8DeviceMotionEvent::initDeviceMotionEventMethodCustom(const v8::FunctionCa llbackInfo<v8::Value>& info) 118 void V8DeviceMotionEvent::initDeviceMotionEventMethodCustom(const v8::FunctionCa llbackInfo<v8::Value>& info)
113 { 119 {
120 // TODO(haraken): This custom binding should mimic auto-generated code more.
114 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initDeviceM otionEvent", "DeviceMotionEvent", info.Holder(), info.GetIsolate()); 121 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initDeviceM otionEvent", "DeviceMotionEvent", info.Holder(), info.GetIsolate());
115 DeviceMotionEvent* impl = V8DeviceMotionEvent::toImpl(info.Holder()); 122 DeviceMotionEvent* impl = V8DeviceMotionEvent::toImpl(info.Holder());
116 v8::Isolate* isolate = info.GetIsolate(); 123 v8::Isolate* isolate = info.GetIsolate();
117 V8StringResource<> type(info[0]); 124 V8StringResource<> type(info[0]);
118 if (!type.prepare()) 125 if (!type.prepare())
119 return; 126 return;
120 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); 127 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
121 bool bubbles = false; 128 bool bubbles = false;
122 V8_CALL(bubbles, info[1], BooleanValue(context), return); 129 if (!info[1]->BooleanValue(context).To(&bubbles))
Yuki 2016/08/26 15:25:01 I think it's not guaranteed that info.Length() > 1
haraken 2016/09/05 00:45:42 In that case, info[1] returns v8::Undefined. So th
130 return;
123 bool cancelable = false; 131 bool cancelable = false;
124 V8_CALL(cancelable, info[2], BooleanValue(context), return); 132 if (!info[2]->BooleanValue(context).To(&cancelable))
133 return;
125 DeviceMotionData::Acceleration* acceleration = readAccelerationArgument(info [3], isolate); 134 DeviceMotionData::Acceleration* acceleration = readAccelerationArgument(info [3], isolate);
126 DeviceMotionData::Acceleration* accelerationIncludingGravity = readAccelerat ionArgument(info[4], isolate); 135 DeviceMotionData::Acceleration* accelerationIncludingGravity = readAccelerat ionArgument(info[4], isolate);
127 DeviceMotionData::RotationRate* rotationRate = readRotationRateArgument(info [5], isolate); 136 DeviceMotionData::RotationRate* rotationRate = readRotationRateArgument(info [5], isolate);
128 bool intervalProvided = !isUndefinedOrNull(info[6]); 137 bool intervalProvided = !isUndefinedOrNull(info[6]);
129 double interval = 0; 138 double interval = 0;
130 if (intervalProvided) { 139 if (intervalProvided) {
131 interval = toRestrictedDouble(isolate, info[6], exceptionState); 140 interval = toRestrictedDouble(isolate, info[6], exceptionState);
132 if (exceptionState.throwIfNeeded()) 141 if (exceptionState.throwIfNeeded())
133 return; 142 return;
134 } 143 }
135 DeviceMotionData* deviceMotionData = DeviceMotionData::create(acceleration, accelerationIncludingGravity, rotationRate, intervalProvided, interval); 144 DeviceMotionData* deviceMotionData = DeviceMotionData::create(acceleration, accelerationIncludingGravity, rotationRate, intervalProvided, interval);
136 impl->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData); 145 impl->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData);
137 } 146 }
138 147
139 } // namespace blink 148 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698