Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved error message modifying frozen object.

  • Loading branch information...
commit 30a22cd40cc9587b1b4f0268d6f34a2c1bd07104 1 parent 623ae4f
@brixen brixen authored
View
4 vm/builtin/access_variable.cpp
@@ -50,7 +50,7 @@ namespace rubinius {
Object* recv = args.recv();
if(CBOOL(recv->frozen_p(state))) {
- Exception::frozen_error(state, call_frame);
+ Exception::frozen_error(state, call_frame, recv);
return 0;
}
@@ -67,7 +67,7 @@ namespace rubinius {
/* The writer case. */
if(access->write()->true_p()) {
if(CBOOL(self->frozen_p(state))) {
- Exception::frozen_error(state, call_frame);
+ Exception::frozen_error(state, call_frame, self);
return 0;
}
View
17 vm/builtin/exception.cpp
@@ -91,9 +91,20 @@ namespace rubinius {
state->raise_exception(exc);
}
- void Exception::frozen_error(STATE, CallFrame* call_frame) {
- Exception* exc = Exception::make_exception(state, G(exc_rte),
- "unable to modify frozen object");
+ Exception* Exception::make_frozen_exception(STATE, Object* obj) {
+ std::ostringstream msg;
+ msg << "can't modify frozen instance of ";
+ msg << obj->class_object(state)->module_name()->debug_str(state);
+
+ return Exception::make_exception(state, G(exc_rte), msg.str().c_str());
+ }
+
+ void Exception::frozen_error(STATE, Object* obj) {
+ RubyException::raise(Exception::make_frozen_exception(state, obj));
+ }
+
+ void Exception::frozen_error(STATE, CallFrame* call_frame, Object* obj) {
+ Exception* exc = Exception::make_frozen_exception(state, obj);
exc->locations(state, Location::from_call_stack(state, call_frame));
state->raise_exception(exc);
}
View
5 vm/builtin/exception.hpp
@@ -52,6 +52,8 @@ namespace rubinius {
static Exception* make_argument_error(STATE, int expected, int given, Symbol* name=0);
static Exception* make_encoding_compatibility_error(STATE, Object* a, Object* b);
+ static Exception* make_frozen_exception(STATE, Object* obj);
+
static void argument_error(STATE, int expected, int given);
static void argument_error(STATE, const char* reason);
static void regexp_error(STATE, const char* reason);
@@ -82,7 +84,8 @@ namespace rubinius {
static void internal_error(STATE, CallFrame* frame, const char* reason);
static void bytecode_error(STATE, CallFrame* frame, CompiledCode* code,
int ip, const char* reason);
- static void frozen_error(STATE, CallFrame* frame);
+ static void frozen_error(STATE, Object* obj);
+ static void frozen_error(STATE, CallFrame* frame, Object* obj);
static void encoding_compatibility_error(STATE, Object* a, Object* b);
static void encoding_compatibility_error(STATE, Object* a, Object* b,
View
3  vm/builtin/object.cpp
@@ -180,8 +180,7 @@ namespace rubinius {
void Object::check_frozen(STATE) {
if(CBOOL(frozen_p(state))) {
- const char* reason = "can't modify frozen object";
- Exception::runtime_error(state, reason);
+ Exception::frozen_error(state, this);
}
}
View
4 vm/instructions.def
@@ -709,7 +709,7 @@ section "Manipulate instance variables"
instruction set_ivar(literal) [ value -- value ]
if(CBOOL(call_frame->self()->frozen_p(state))) {
- Exception::frozen_error(state, call_frame);
+ Exception::frozen_error(state, call_frame, call_frame->self());
RUN_EXCEPTION();
}
Symbol* sym = as<Symbol>(call_frame->compiled_code->literals()->at(state, literal));
@@ -2178,7 +2178,7 @@ instruction check_frozen() [ value -- value ]
Object* value = stack_top();
if(value->reference_p() && value->is_frozen_p()) {
- Exception::frozen_error(state, call_frame);
+ Exception::frozen_error(state, call_frame, value);
RUN_EXCEPTION();
}
end
View
4 vm/llvm/jit_util.cpp
@@ -76,7 +76,7 @@ extern "C" {
Object* rbx_check_frozen(STATE, CallFrame* call_frame, Object* obj) {
if(obj->reference_p() && obj->is_frozen_p()) {
- Exception::frozen_error(state, call_frame);
+ Exception::frozen_error(state, call_frame, obj);
return NULL;
}
@@ -981,7 +981,7 @@ extern "C" {
Object* rbx_set_ivar(STATE, CallFrame* call_frame, Object* self, Symbol* name, Object* val) {
if(self->reference_p() && self->is_frozen_p()) {
- Exception::frozen_error(state, call_frame);
+ Exception::frozen_error(state, call_frame, self);
return NULL;
}
Please sign in to comment.
Something went wrong with that request. Please try again.