From d4655840f69e0cce077749ad4a2c256e03bb8f66 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 5 Feb 2011 02:29:18 +0000 Subject: * ext/json/ext/parser/parser.h (GET_PARSER): raise TypeError. * ext/json/ext/parser/parser.rl (cParser_initialize): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/json/ext/parser/parser.c | 2 +- ext/json/ext/parser/parser.h | 2 +- ext/json/ext/parser/parser.rl | 2 +- tests/test_json.rb | 7 +++++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index d223a86..89f9181 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -1645,7 +1645,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) GET_PARSER_INIT; if (json->Vsource) { - rb_raise(rb_eArgError, "already initialized instance"); + rb_raise(rb_eTypeError, "already initialized instance"); } rb_scan_args(argc, argv, "11", &source, &opts); source = convert_encoding(StringValue(source)); diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h index 904156f..2be640e 100644 --- a/ext/json/ext/parser/parser.h +++ b/ext/json/ext/parser/parser.h @@ -52,7 +52,7 @@ typedef struct JSON_ParserStruct { #define GET_PARSER \ GET_PARSER_INIT; \ - if (!json->Vsource) rb_raise(rb_eArgError, "uninitialized instance") + if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance") #define GET_PARSER_INIT \ JSON_Parser *json; \ Data_Get_Struct(self, JSON_Parser, json) diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index eb0a6ba..44ddfa6 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -643,7 +643,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) GET_PARSER_INIT; if (json->Vsource) { - rb_raise(rb_eArgError, "already initialized instance"); + rb_raise(rb_eTypeError, "already initialized instance"); } rb_scan_args(argc, argv, "11", &source, &opts); source = convert_encoding(StringValue(source)); diff --git a/tests/test_json.rb b/tests/test_json.rb index 4fc6a28..d320498 100755 --- a/tests/test_json.rb +++ b/tests/test_json.rb @@ -406,4 +406,11 @@ EOT json5 = JSON([orig = 1 << 64]) assert_equal orig, JSON[json5][0] end + + if defined?(JSON::Ext::Parser) + def test_uninitialized + parser = JSON::Ext::Parser.allocate + assert_raise(TypeError) {parser.source} + end + end end -- cgit v1.2.3-24-ge0c7