There's a subtle but important difference between "value->IsEmpty()" and "value.IsEmpty()" ;-)
On Thu, May 15, 2014 at 1:36 AM, Abhishek Kona <abhishek.k...@gmail.com>wrote: > I have some v8 Code which tries to Parse JSON I get a SIGSEGV once in a > while when I try to access the value. I am very confused about what is > happening. > Any help would be greatly appreciated. > > The code to Parse JSON is > > v8::Handle<v8::Value> FromJSONString( > v8::Handle<v8::Value> json_string) { > v8::HandleScope scope; > v8::Handle<v8::Context> context = v8::Context::GetCurrent(); > v8::Handle<v8::Object> global = context->Global(); > > v8::Handle<v8::Value> JSON_value = global->Get(v8::String::New("JSON")); > if (!IsObject(JSON_value)) { > return scope.Close(v8::Undefined()); > } > v8::Handle<v8::Object> JSON = JSON_value->ToObject(); > > v8::Handle<v8::Value> JSON_parse_value = > JSON->Get(v8::String::New("parse")); > > if (JSON_parse_value.IsEmpty() || JSON_parse_value->IsNull() || > JSON_parse_value->IsUndefined() ||!JSON_parse_value->IsFunction()) { > return scope.Close(v8::Undefined()); > } > > > v8::Handle<v8::Function> JSON_parse = > v8::Handle<v8::Function>::Cast(JSON_parse_value); > > return scope.Close(JSON_parse->Call(JSON, 1, &json_string)); > } > > And the code which calls this is at => For some reason accessing Value > results in a SIGSEGV. > > bool extractSource(std::string* source, std::string& body) { > v8::HandleScope scope; // this is needed and clears the memory > if (body.empty()) { > return false; > } > v8::Handle<v8::Value> value = v8_server_utils::FromJSONString(body); > if (value->IsEmpty()) { // CRASHES HERE. > return false; > } > if (value->IsNull()) { > return false; > } > if (value->IsUndefined()) { > return false; > } > if (!value->IsObject()) { > return false; > } > auto object = value->ToObject(); > auto source_key = v8::String::New("source"); > if (object.IsEmpty() || object->IsNull() || object->IsUndefined() || > !object->Has(source_key)) { > return false; > } > auto source_obj = object->Get(source_key); > *source = v8_server_utils::JSStringToCString(source_obj->ToString()); > return true; > } > > > > -- > -- > v8-users mailing list > v8-users@googlegroups.com > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to v8-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.