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

Side by Side Diff: src/wasm/wasm-objects.cc

Issue 2526783002: [base] Define CHECK comparison for signed vs. unsigned (Closed)
Patch Set: Extend test case Created 4 years 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 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/wasm/wasm-objects.h" 5 #include "src/wasm/wasm-objects.h"
6 6
7 #include "src/wasm/module-decoder.h" 7 #include "src/wasm/module-decoder.h"
8 #include "src/wasm/wasm-module.h" 8 #include "src/wasm/wasm-module.h"
9 9
10 #define TRACE(...) \ 10 #define TRACE(...) \
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 static uint32_t SafeUint32(Object* value) { 45 static uint32_t SafeUint32(Object* value) {
46 if (value->IsSmi()) { 46 if (value->IsSmi()) {
47 int32_t val = Smi::cast(value)->value(); 47 int32_t val = Smi::cast(value)->value();
48 CHECK_GE(val, 0); 48 CHECK_GE(val, 0);
49 return static_cast<uint32_t>(val); 49 return static_cast<uint32_t>(val);
50 } 50 }
51 DCHECK(value->IsHeapNumber()); 51 DCHECK(value->IsHeapNumber());
52 HeapNumber* num = HeapNumber::cast(value); 52 HeapNumber* num = HeapNumber::cast(value);
53 CHECK_GE(num->value(), 0.0); 53 CHECK_GE(num->value(), 0.0);
54 CHECK_LE(num->value(), static_cast<double>(kMaxUInt32)); 54 CHECK_LE(num->value(), kMaxUInt32);
55 return static_cast<uint32_t>(num->value()); 55 return static_cast<uint32_t>(num->value());
56 } 56 }
57 57
58 static int32_t SafeInt32(Object* value) { 58 static int32_t SafeInt32(Object* value) {
59 if (value->IsSmi()) { 59 if (value->IsSmi()) {
60 return Smi::cast(value)->value(); 60 return Smi::cast(value)->value();
61 } 61 }
62 DCHECK(value->IsHeapNumber()); 62 DCHECK(value->IsHeapNumber());
63 HeapNumber* num = HeapNumber::cast(value); 63 HeapNumber* num = HeapNumber::cast(value);
64 CHECK_GE(num->value(), static_cast<double>(Smi::kMinValue)); 64 CHECK_GE(num->value(), Smi::kMinValue);
65 CHECK_LE(num->value(), static_cast<double>(Smi::kMaxValue)); 65 CHECK_LE(num->value(), Smi::kMaxValue);
66 return static_cast<int32_t>(num->value()); 66 return static_cast<int32_t>(num->value());
67 } 67 }
68 68
69 Handle<WasmModuleObject> WasmModuleObject::New( 69 Handle<WasmModuleObject> WasmModuleObject::New(
70 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { 70 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) {
71 ModuleOrigin origin = compiled_module->module()->origin; 71 ModuleOrigin origin = compiled_module->module()->origin;
72 72
73 Handle<JSObject> module_object; 73 Handle<JSObject> module_object;
74 if (origin == ModuleOrigin::kWasmOrigin) { 74 if (origin == ModuleOrigin::kWasmOrigin) {
75 Handle<JSFunction> module_cons( 75 Handle<JSFunction> module_cons(
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 uint32_t WasmCompiledModule::default_mem_size() const { 388 uint32_t WasmCompiledModule::default_mem_size() const {
389 return min_mem_pages() * WasmModule::kPageSize; 389 return min_mem_pages() * WasmModule::kPageSize;
390 } 390 }
391 391
392 Vector<const uint8_t> WasmCompiledModule::GetRawFunctionName( 392 Vector<const uint8_t> WasmCompiledModule::GetRawFunctionName(
393 uint32_t func_index) { 393 uint32_t func_index) {
394 DCHECK_GT(module()->functions.size(), func_index); 394 DCHECK_GT(module()->functions.size(), func_index);
395 WasmFunction& function = module()->functions[func_index]; 395 WasmFunction& function = module()->functions[func_index];
396 SeqOneByteString* bytes = ptr_to_module_bytes(); 396 SeqOneByteString* bytes = ptr_to_module_bytes();
397 DCHECK_GE(static_cast<size_t>(bytes->length()), function.name_offset); 397 DCHECK_GE(bytes->length(), function.name_offset);
398 DCHECK_GE(static_cast<size_t>(bytes->length() - function.name_offset), 398 DCHECK_GE(bytes->length() - function.name_offset, function.name_length);
399 function.name_length);
400 return Vector<const uint8_t>(bytes->GetCharsAddress() + function.name_offset, 399 return Vector<const uint8_t>(bytes->GetCharsAddress() + function.name_offset,
401 function.name_length); 400 function.name_length);
402 } 401 }
403 402
404 int WasmCompiledModule::GetFunctionOffset(uint32_t func_index) const { 403 int WasmCompiledModule::GetFunctionOffset(uint32_t func_index) const {
405 std::vector<WasmFunction>& functions = module()->functions; 404 std::vector<WasmFunction>& functions = module()->functions;
406 if (static_cast<uint32_t>(func_index) >= functions.size()) return -1; 405 if (static_cast<uint32_t>(func_index) >= functions.size()) return -1;
407 DCHECK_GE(static_cast<uint32_t>(kMaxInt), 406 DCHECK_GE(kMaxInt, functions[func_index].code_start_offset);
408 functions[func_index].code_start_offset);
409 return static_cast<int>(functions[func_index].code_start_offset); 407 return static_cast<int>(functions[func_index].code_start_offset);
410 } 408 }
411 409
412 int WasmCompiledModule::GetContainingFunction(uint32_t byte_offset) const { 410 int WasmCompiledModule::GetContainingFunction(uint32_t byte_offset) const {
413 std::vector<WasmFunction>& functions = module()->functions; 411 std::vector<WasmFunction>& functions = module()->functions;
414 412
415 // Binary search for a function containing the given position. 413 // Binary search for a function containing the given position.
416 int left = 0; // inclusive 414 int left = 0; // inclusive
417 int right = static_cast<int>(functions.size()); // exclusive 415 int right = static_cast<int>(functions.size()); // exclusive
418 if (right == 0) return false; 416 if (right == 0) return false;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 !array->get(kPreviousInstanceWrapper)->IsFixedArray()) 562 !array->get(kPreviousInstanceWrapper)->IsFixedArray())
565 return false; 563 return false;
566 return true; 564 return true;
567 } 565 }
568 566
569 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance, 567 void WasmInstanceWrapper::set_instance_object(Handle<JSObject> instance,
570 Isolate* isolate) { 568 Isolate* isolate) {
571 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance); 569 Handle<WeakCell> cell = isolate->factory()->NewWeakCell(instance);
572 set(kWrapperInstanceObject, *cell); 570 set(kWrapperInstanceObject, *cell);
573 } 571 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698