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

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

Issue 970403003: bindings: Use V8 MaybeLocal APIs in V8DeviceMotionEventCustom (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
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 16 matching lines...) Expand all
27 #include "bindings/modules/v8/V8DeviceMotionEvent.h" 27 #include "bindings/modules/v8/V8DeviceMotionEvent.h"
28 28
29 #include "bindings/core/v8/V8Binding.h" 29 #include "bindings/core/v8/V8Binding.h"
30 #include "modules/device_orientation/DeviceMotionData.h" 30 #include "modules/device_orientation/DeviceMotionData.h"
31 #include <v8.h> 31 #include <v8.h>
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, ExceptionState& exceptionState)
38 { 38 {
39 if (isUndefinedOrNull(value)) 39 if (isUndefinedOrNull(value))
40 return nullptr; 40 return nullptr;
41 41
42 // Given the test above, this will always yield an object. 42 v8::Local<v8::Object> object;
43 v8::Local<v8::Object> object = value->ToObject(isolate); 43 CALL_V8_MAYBELOCAL(object, isolate, value->ToObject(isolate->GetCurrentConte xt()), exceptionState, nullptr);
44 44
45 v8::Local<v8::Value> xValue = object->Get(v8AtomicString(isolate, "x")); 45 v8::Local<v8::Value> xValue = object->Get(v8AtomicString(isolate, "x"));
46 if (xValue.IsEmpty()) 46 if (xValue.IsEmpty())
47 return nullptr; 47 return nullptr;
48 bool canProvideX = !isUndefinedOrNull(xValue); 48 bool canProvideX = !isUndefinedOrNull(xValue);
49 double x = xValue->NumberValue(); 49 double x = xValue->NumberValue();
50 50
51 v8::Local<v8::Value> yValue = object->Get(v8AtomicString(isolate, "y")); 51 v8::Local<v8::Value> yValue = object->Get(v8AtomicString(isolate, "y"));
52 if (yValue.IsEmpty()) 52 if (yValue.IsEmpty())
53 return nullptr; 53 return nullptr;
54 bool canProvideY = !isUndefinedOrNull(yValue); 54 bool canProvideY = !isUndefinedOrNull(yValue);
55 double y = yValue->NumberValue(); 55 double y = yValue->NumberValue();
56 56
57 v8::Local<v8::Value> zValue = object->Get(v8AtomicString(isolate, "z")); 57 v8::Local<v8::Value> zValue = object->Get(v8AtomicString(isolate, "z"));
58 if (zValue.IsEmpty()) 58 if (zValue.IsEmpty())
59 return nullptr; 59 return nullptr;
60 bool canProvideZ = !isUndefinedOrNull(zValue); 60 bool canProvideZ = !isUndefinedOrNull(zValue);
61 double z = zValue->NumberValue(); 61 double z = zValue->NumberValue();
62 62
63 if (!canProvideX && !canProvideY && !canProvideZ) 63 if (!canProvideX && !canProvideY && !canProvideZ)
64 return nullptr; 64 return nullptr;
65 65
66 return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y , canProvideZ, z); 66 return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y , canProvideZ, z);
67 } 67 }
68 68
69 DeviceMotionData::RotationRate* readRotationRateArgument(v8::Local<v8::Value> va lue, v8::Isolate* isolate) 69 DeviceMotionData::RotationRate* readRotationRateArgument(v8::Local<v8::Value> va lue, v8::Isolate* isolate, ExceptionState& exceptionState)
70 { 70 {
71 if (isUndefinedOrNull(value)) 71 if (isUndefinedOrNull(value))
72 return nullptr; 72 return nullptr;
73 73
74 // Given the test above, this will always yield an object. 74 v8::Local<v8::Object> object;
75 v8::Local<v8::Object> object = value->ToObject(isolate); 75 CALL_V8_MAYBELOCAL(object, isolate, value->ToObject(isolate->GetCurrentConte xt()), exceptionState, nullptr);
76 76
77 v8::Local<v8::Value> alphaValue = object->Get(v8AtomicString(isolate, "alpha ")); 77 v8::Local<v8::Value> alphaValue = object->Get(v8AtomicString(isolate, "alpha "));
78 if (alphaValue.IsEmpty()) 78 if (alphaValue.IsEmpty())
79 return nullptr; 79 return nullptr;
80 bool canProvideAlpha = !isUndefinedOrNull(alphaValue); 80 bool canProvideAlpha = !isUndefinedOrNull(alphaValue);
81 double alpha = alphaValue->NumberValue(); 81 double alpha = alphaValue->NumberValue();
82 82
83 v8::Local<v8::Value> betaValue = object->Get(v8AtomicString(isolate, "beta") ); 83 v8::Local<v8::Value> betaValue = object->Get(v8AtomicString(isolate, "beta") );
84 if (betaValue.IsEmpty()) 84 if (betaValue.IsEmpty())
85 return nullptr; 85 return nullptr;
(...skipping 17 matching lines...) Expand all
103 void V8DeviceMotionEvent::initDeviceMotionEventMethodCustom(const v8::FunctionCa llbackInfo<v8::Value>& info) 103 void V8DeviceMotionEvent::initDeviceMotionEventMethodCustom(const v8::FunctionCa llbackInfo<v8::Value>& info)
104 { 104 {
105 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initDeviceM otionEvent", "DeviceMotionEvent", info.Holder(), info.GetIsolate()); 105 ExceptionState exceptionState(ExceptionState::ExecutionContext, "initDeviceM otionEvent", "DeviceMotionEvent", info.Holder(), info.GetIsolate());
106 DeviceMotionEvent* impl = V8DeviceMotionEvent::toImpl(info.Holder()); 106 DeviceMotionEvent* impl = V8DeviceMotionEvent::toImpl(info.Holder());
107 v8::Isolate* isolate = info.GetIsolate(); 107 v8::Isolate* isolate = info.GetIsolate();
108 V8StringResource<> type(info[0]); 108 V8StringResource<> type(info[0]);
109 if (!type.prepare()) 109 if (!type.prepare())
110 return; 110 return;
111 bool bubbles = info[1]->BooleanValue(); 111 bool bubbles = info[1]->BooleanValue();
112 bool cancelable = info[2]->BooleanValue(); 112 bool cancelable = info[2]->BooleanValue();
113 DeviceMotionData::Acceleration* acceleration = readAccelerationArgument(info [3], isolate); 113 DeviceMotionData::Acceleration* acceleration = readAccelerationArgument(info [3], isolate, exceptionState);
114 DeviceMotionData::Acceleration* accelerationIncludingGravity = readAccelerat ionArgument(info[4], isolate); 114 DeviceMotionData::Acceleration* accelerationIncludingGravity = readAccelerat ionArgument(info[4], isolate, exceptionState);
115 DeviceMotionData::RotationRate* rotationRate = readRotationRateArgument(info [5], isolate); 115 DeviceMotionData::RotationRate* rotationRate = readRotationRateArgument(info [5], isolate, exceptionState);
116 if (exceptionState.throwIfNeeded())
117 return;
118
116 bool intervalProvided = !isUndefinedOrNull(info[6]); 119 bool intervalProvided = !isUndefinedOrNull(info[6]);
117 double interval = 0; 120 double interval = 0;
118 if (intervalProvided) { 121 if (intervalProvided) {
119 interval = toRestrictedDouble(info[6], exceptionState); 122 interval = toRestrictedDouble(info[6], exceptionState);
120 if (exceptionState.throwIfNeeded()) 123 if (exceptionState.throwIfNeeded())
121 return; 124 return;
122 } 125 }
123 DeviceMotionData* deviceMotionData = DeviceMotionData::create(acceleration, accelerationIncludingGravity, rotationRate, intervalProvided, interval); 126 DeviceMotionData* deviceMotionData = DeviceMotionData::create(acceleration, accelerationIncludingGravity, rotationRate, intervalProvided, interval);
124 impl->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData); 127 impl->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData);
125 } 128 }
126 129
127 } // namespace blink 130 } // namespace blink
OLDNEW
« Source/bindings/core/v8/V8BindingMacros.h ('K') | « Source/bindings/core/v8/V8BindingMacros.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698