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

Side by Side Diff: lib/error.cc

Issue 10874072: Use the return value of vm native methods to set the return value, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "lib/error.h" 5 #include "lib/error.h"
6 6
7 #include "vm/bootstrap_natives.h" 7 #include "vm/bootstrap_natives.h"
8 #include "vm/exceptions.h" 8 #include "vm/exceptions.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/runtime_entry.h" 10 #include "vm/runtime_entry.h"
(...skipping 28 matching lines...) Expand all
39 intptr_t from_line, from_column; 39 intptr_t from_line, from_column;
40 script.GetTokenLocation(assertion_start, &from_line, &from_column); 40 script.GetTokenLocation(assertion_start, &from_line, &from_column);
41 intptr_t to_line, to_column; 41 intptr_t to_line, to_column;
42 script.GetTokenLocation(assertion_end, &to_line, &to_column); 42 script.GetTokenLocation(assertion_end, &to_line, &to_column);
43 Exceptions::SetField(assertion_error, cls, "failedAssertion", String::Handle( 43 Exceptions::SetField(assertion_error, cls, "failedAssertion", String::Handle(
44 script.GetSnippet(from_line, from_column, to_line, to_column))); 44 script.GetSnippet(from_line, from_column, to_line, to_column)));
45 45
46 // Throw AssertionError instance. 46 // Throw AssertionError instance.
47 Exceptions::Throw(assertion_error); 47 Exceptions::Throw(assertion_error);
48 UNREACHABLE(); 48 UNREACHABLE();
49 return Object::null();
49 } 50 }
50 51
51 52
52 // Allocate and throw a new TypeError. 53 // Allocate and throw a new TypeError.
53 // Arg0: index of the token of the failed type check. 54 // Arg0: index of the token of the failed type check.
54 // Arg1: src value. 55 // Arg1: src value.
55 // Arg2: dst type name. 56 // Arg2: dst type name.
56 // Arg3: dst name. 57 // Arg3: dst name.
57 // Arg4: malformed type error message. 58 // Arg4: malformed type error message.
58 // Return value: none, throws an exception. 59 // Return value: none, throws an exception.
59 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) { 60 DEFINE_NATIVE_ENTRY(TypeError_throwNew, 5) {
60 // No need to type check the arguments. This function can only be called 61 // No need to type check the arguments. This function can only be called
61 // internally from the VM. 62 // internally from the VM.
62 intptr_t location = Smi::CheckedHandle(arguments->At(0)).Value(); 63 intptr_t location = Smi::CheckedHandle(arguments->At(0)).Value();
63 const Instance& src_value = Instance::CheckedHandle(arguments->At(1)); 64 const Instance& src_value = Instance::CheckedHandle(arguments->At(1));
64 const String& dst_type_name = String::CheckedHandle(arguments->At(2)); 65 const String& dst_type_name = String::CheckedHandle(arguments->At(2));
65 const String& dst_name = String::CheckedHandle(arguments->At(3)); 66 const String& dst_name = String::CheckedHandle(arguments->At(3));
66 const String& malformed_error = String::CheckedHandle(arguments->At(4)); 67 const String& malformed_error = String::CheckedHandle(arguments->At(4));
67 const String& src_type_name = 68 const String& src_type_name =
68 String::Handle(Type::Handle(src_value.GetType()).UserVisibleName()); 69 String::Handle(Type::Handle(src_value.GetType()).UserVisibleName());
69 Exceptions::CreateAndThrowTypeError(location, src_type_name, 70 Exceptions::CreateAndThrowTypeError(location, src_type_name,
70 dst_type_name, dst_name, malformed_error); 71 dst_type_name, dst_name, malformed_error);
72 UNREACHABLE();
73 return Object::null();
71 } 74 }
72 75
73 76
74 // Allocate and throw a new FallThroughError. 77 // Allocate and throw a new FallThroughError.
75 // Arg0: index of the case clause token into which we fall through. 78 // Arg0: index of the case clause token into which we fall through.
76 // Return value: none, throws an exception. 79 // Return value: none, throws an exception.
77 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) { 80 DEFINE_NATIVE_ENTRY(FallThroughError_throwNew, 1) {
78 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0)); 81 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0));
79 intptr_t fallthrough_pos = smi_pos.Value(); 82 intptr_t fallthrough_pos = smi_pos.Value();
80 83
(...skipping 10 matching lines...) Expand all
91 Exceptions::SetField(fallthrough_error, cls, "url", 94 Exceptions::SetField(fallthrough_error, cls, "url",
92 String::Handle(script.url())); 95 String::Handle(script.url()));
93 intptr_t line, column; 96 intptr_t line, column;
94 script.GetTokenLocation(fallthrough_pos, &line, &column); 97 script.GetTokenLocation(fallthrough_pos, &line, &column);
95 Exceptions::SetField(fallthrough_error, cls, "line", 98 Exceptions::SetField(fallthrough_error, cls, "line",
96 Smi::Handle(Smi::New(line))); 99 Smi::Handle(Smi::New(line)));
97 100
98 // Throw FallThroughError instance. 101 // Throw FallThroughError instance.
99 Exceptions::Throw(fallthrough_error); 102 Exceptions::Throw(fallthrough_error);
100 UNREACHABLE(); 103 UNREACHABLE();
104 return Object::null();
101 } 105 }
102 106
103 107
104 // Allocate and throw StaticResolutionException. 108 // Allocate and throw StaticResolutionException.
105 // Arg0: index of the static call that was not resolved at compile time. 109 // Arg0: index of the static call that was not resolved at compile time.
106 // Return value: none, throws an exception. 110 // Return value: none, throws an exception.
107 DEFINE_NATIVE_ENTRY(StaticResolutionException_throwNew, 1) { 111 DEFINE_NATIVE_ENTRY(StaticResolutionException_throwNew, 1) {
108 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0)); 112 GET_NATIVE_ARGUMENT(Smi, smi_pos, arguments->At(0));
109 intptr_t call_pos = smi_pos.Value(); 113 intptr_t call_pos = smi_pos.Value();
110 // Allocate a new instance of type StaticResolutionException. 114 // Allocate a new instance of type StaticResolutionException.
111 const Instance& resolution_exception = 115 const Instance& resolution_exception =
112 Instance::Handle(Exceptions::NewInstance("StaticResolutionException")); 116 Instance::Handle(Exceptions::NewInstance("StaticResolutionException"));
113 ASSERT(!resolution_exception.IsNull()); 117 ASSERT(!resolution_exception.IsNull());
114 118
115 // Initialize 'url', 'line', and 'column' fields. 119 // Initialize 'url', 'line', and 'column' fields.
116 DartFrameIterator iterator; 120 DartFrameIterator iterator;
117 iterator.NextFrame(); // Skip native call. 121 iterator.NextFrame(); // Skip native call.
118 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator)); 122 const Script& script = Script::Handle(Exceptions::GetCallerScript(&iterator));
119 const Class& cls = Class::Handle(resolution_exception.clazz()); 123 const Class& cls = Class::Handle(resolution_exception.clazz());
120 Exceptions::SetLocationFields(resolution_exception, cls, script, call_pos); 124 Exceptions::SetLocationFields(resolution_exception, cls, script, call_pos);
121 125
122 intptr_t line, column; 126 intptr_t line, column;
123 script.GetTokenLocation(call_pos, &line, &column); 127 script.GetTokenLocation(call_pos, &line, &column);
124 Exceptions::SetField(resolution_exception, cls, "failedResolutionLine", 128 Exceptions::SetField(resolution_exception, cls, "failedResolutionLine",
125 String::Handle(script.GetLine(line))); 129 String::Handle(script.GetLine(line)));
126 130
127 Exceptions::Throw(resolution_exception); 131 Exceptions::Throw(resolution_exception);
128 UNREACHABLE(); 132 UNREACHABLE();
133 return Object::null();
129 } 134 }
130 135
131 } // namespace dart 136 } // namespace dart
OLDNEW
« no previous file with comments | « lib/double.cc ('k') | lib/growable_array.cc » ('j') | vm/bootstrap_natives.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698