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

Side by Side Diff: src/field-type.cc

Issue 2292953002: Make FieldType::None() non-nullptr value to avoid undefined behaviour (Closed)
Patch Set: (fix build by removing unused var in test) 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
« no previous file with comments | « no previous file | test/cctest/test-field-type-tracking.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/field-type.h" 5 #include "src/field-type.h"
6 6
7 #include "src/handles-inl.h" 7 #include "src/handles-inl.h"
8 #include "src/ostreams.h" 8 #include "src/ostreams.h"
9 #include "src/types.h" 9 #include "src/types.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 13
14 // static 14 // static
15 FieldType* FieldType::None() { 15 FieldType* FieldType::None() {
16 return reinterpret_cast<FieldType*>(Smi::FromInt(0)); 16 // Do not Smi::FromInt(0) here or for Any(), as that may translate
17 // as `nullptr` which is not a valid value for `this`.
18 return reinterpret_cast<FieldType*>(Smi::FromInt(2));
17 } 19 }
18 20
19 // static 21 // static
20 FieldType* FieldType::Any() { 22 FieldType* FieldType::Any() {
21 return reinterpret_cast<FieldType*>(Smi::FromInt(1)); 23 return reinterpret_cast<FieldType*>(Smi::FromInt(1));
22 } 24 }
23 25
24 // static 26 // static
25 Handle<FieldType> FieldType::None(Isolate* isolate) { 27 Handle<FieldType> FieldType::None(Isolate* isolate) {
26 return handle(None(), isolate); 28 return handle(None(), isolate);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } else if (IsNone()) { 84 } else if (IsNone()) {
83 os << "None"; 85 os << "None";
84 } else { 86 } else {
85 DCHECK(IsClass()); 87 DCHECK(IsClass());
86 os << "Class(" << static_cast<void*>(*AsClass()) << ")"; 88 os << "Class(" << static_cast<void*>(*AsClass()) << ")";
87 } 89 }
88 } 90 }
89 91
90 } // namespace internal 92 } // namespace internal
91 } // namespace v8 93 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-field-type-tracking.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698