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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/ScriptValue.h

Issue 2817533003: Replace ASSERT, RELEASE_ASSERT, and ASSERT_NOT_REACHED in bindings (Closed)
Patch Set: fixed dcheck build error Created 3 years, 8 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) 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 69
70 ScriptValue() {} 70 ScriptValue() {}
71 71
72 ScriptValue(ScriptState* script_state, v8::Local<v8::Value> value) 72 ScriptValue(ScriptState* script_state, v8::Local<v8::Value> value)
73 : script_state_(script_state), 73 : script_state_(script_state),
74 value_(value.IsEmpty() ? nullptr 74 value_(value.IsEmpty() ? nullptr
75 : SharedPersistent<v8::Value>::Create( 75 : SharedPersistent<v8::Value>::Create(
76 value, 76 value,
77 script_state->GetIsolate())) { 77 script_state->GetIsolate())) {
78 ASSERT(IsEmpty() || script_state_); 78 DCHECK(IsEmpty() || script_state_);
79 } 79 }
80 80
81 template <typename T> 81 template <typename T>
82 ScriptValue(ScriptState* script_state, v8::MaybeLocal<T> value) 82 ScriptValue(ScriptState* script_state, v8::MaybeLocal<T> value)
83 : script_state_(script_state), 83 : script_state_(script_state),
84 value_(value.IsEmpty() ? nullptr 84 value_(value.IsEmpty() ? nullptr
85 : SharedPersistent<v8::Value>::Create( 85 : SharedPersistent<v8::Value>::Create(
86 value.ToLocalChecked(), 86 value.ToLocalChecked(),
87 script_state->GetIsolate())) { 87 script_state->GetIsolate())) {
88 ASSERT(IsEmpty() || script_state_); 88 DCHECK(IsEmpty() || script_state_);
89 } 89 }
90 90
91 ScriptValue(const ScriptValue& value) 91 ScriptValue(const ScriptValue& value)
92 : script_state_(value.script_state_), value_(value.value_) { 92 : script_state_(value.script_state_), value_(value.value_) {
93 ASSERT(IsEmpty() || script_state_); 93 DCHECK(IsEmpty() || script_state_);
94 } 94 }
95 95
96 ScriptState* GetScriptState() const { return script_state_.Get(); } 96 ScriptState* GetScriptState() const { return script_state_.Get(); }
97 97
98 v8::Isolate* GetIsolate() const { 98 v8::Isolate* GetIsolate() const {
99 return script_state_ ? script_state_->GetIsolate() 99 return script_state_ ? script_state_->GetIsolate()
100 : v8::Isolate::GetCurrent(); 100 : v8::Isolate::GetCurrent();
101 } 101 }
102 102
103 v8::Local<v8::Context> GetContext() const { 103 v8::Local<v8::Context> GetContext() const {
104 ASSERT(script_state_.Get()); 104 DCHECK(script_state_.Get());
105 return script_state_->GetContext(); 105 return script_state_->GetContext();
106 } 106 }
107 107
108 ScriptValue& operator=(const ScriptValue& value) { 108 ScriptValue& operator=(const ScriptValue& value) {
109 if (this != &value) { 109 if (this != &value) {
110 script_state_ = value.script_state_; 110 script_state_ = value.script_state_;
111 value_ = value.value_; 111 value_ = value.value_;
112 } 112 }
113 return *this; 113 return *this;
114 } 114 }
115 115
116 bool operator==(const ScriptValue& value) const { 116 bool operator==(const ScriptValue& value) const {
117 if (IsEmpty()) 117 if (IsEmpty())
118 return value.IsEmpty(); 118 return value.IsEmpty();
119 if (value.IsEmpty()) 119 if (value.IsEmpty())
120 return false; 120 return false;
121 return *value_ == *value.value_; 121 return *value_ == *value.value_;
122 } 122 }
123 123
124 bool operator!=(const ScriptValue& value) const { return !operator==(value); } 124 bool operator!=(const ScriptValue& value) const { return !operator==(value); }
125 125
126 // This creates a new local Handle; Don't use this in performance-sensitive 126 // This creates a new local Handle; Don't use this in performance-sensitive
127 // places. 127 // places.
128 bool IsFunction() const { 128 bool IsFunction() const {
129 ASSERT(!IsEmpty()); 129 DCHECK(!IsEmpty());
130 v8::Local<v8::Value> value = V8Value(); 130 v8::Local<v8::Value> value = V8Value();
131 return !value.IsEmpty() && value->IsFunction(); 131 return !value.IsEmpty() && value->IsFunction();
132 } 132 }
133 133
134 // This creates a new local Handle; Don't use this in performance-sensitive 134 // This creates a new local Handle; Don't use this in performance-sensitive
135 // places. 135 // places.
136 bool IsNull() const { 136 bool IsNull() const {
137 ASSERT(!IsEmpty()); 137 DCHECK(!IsEmpty());
138 v8::Local<v8::Value> value = V8Value(); 138 v8::Local<v8::Value> value = V8Value();
139 return !value.IsEmpty() && value->IsNull(); 139 return !value.IsEmpty() && value->IsNull();
140 } 140 }
141 141
142 // This creates a new local Handle; Don't use this in performance-sensitive 142 // This creates a new local Handle; Don't use this in performance-sensitive
143 // places. 143 // places.
144 bool IsUndefined() const { 144 bool IsUndefined() const {
145 ASSERT(!IsEmpty()); 145 DCHECK(!IsEmpty());
146 v8::Local<v8::Value> value = V8Value(); 146 v8::Local<v8::Value> value = V8Value();
147 return !value.IsEmpty() && value->IsUndefined(); 147 return !value.IsEmpty() && value->IsUndefined();
148 } 148 }
149 149
150 // This creates a new local Handle; Don't use this in performance-sensitive 150 // This creates a new local Handle; Don't use this in performance-sensitive
151 // places. 151 // places.
152 bool IsObject() const { 152 bool IsObject() const {
153 ASSERT(!IsEmpty()); 153 DCHECK(!IsEmpty());
154 v8::Local<v8::Value> value = V8Value(); 154 v8::Local<v8::Value> value = V8Value();
155 return !value.IsEmpty() && value->IsObject(); 155 return !value.IsEmpty() && value->IsObject();
156 } 156 }
157 157
158 bool IsEmpty() const { return !value_.Get() || value_->IsEmpty(); } 158 bool IsEmpty() const { return !value_.Get() || value_->IsEmpty(); }
159 159
160 void Clear() { value_ = nullptr; } 160 void Clear() { value_ = nullptr; }
161 161
162 v8::Local<v8::Value> V8Value() const; 162 v8::Local<v8::Value> V8Value() const;
163 // Returns v8Value() if a given ScriptState is the same as the 163 // Returns v8Value() if a given ScriptState is the same as the
164 // ScriptState which is associated with this ScriptValue. Otherwise 164 // ScriptState which is associated with this ScriptValue. Otherwise
165 // this "clones" the v8 value and returns it. 165 // this "clones" the v8 value and returns it.
166 v8::Local<v8::Value> V8ValueFor(ScriptState*) const; 166 v8::Local<v8::Value> V8ValueFor(ScriptState*) const;
167 167
168 bool ToString(String&) const; 168 bool ToString(String&) const;
169 169
170 static ScriptValue CreateNull(ScriptState*); 170 static ScriptValue CreateNull(ScriptState*);
171 171
172 private: 172 private:
173 RefPtr<ScriptState> script_state_; 173 RefPtr<ScriptState> script_state_;
174 RefPtr<SharedPersistent<v8::Value>> value_; 174 RefPtr<SharedPersistent<v8::Value>> value_;
175 }; 175 };
176 176
177 } // namespace blink 177 } // namespace blink
178 178
179 #endif // ScriptValue_h 179 #endif // ScriptValue_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698