From 6974e4b2c7633f1844df0aecd77e90f68c16fbc4 Mon Sep 17 00:00:00 2001 From: "christian.plesner.hansen@gmail.com" Date: Wed, 10 Sep 2008 11:41:48 +0000 Subject: [PATCH] Fixed bug #57. Introduced String::Utf8Value and replaced a bunch of uses of String::AsciiValue with String::Utf8Value. Fixed shell sample 'load' so it doesn't print error messages. git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@254 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 19 ++++++++++++++++ samples/process.cc | 12 +++++----- samples/shell.cc | 40 ++++++++++++++++++++++----------- src/api.cc | 45 +++++++++++++++++++++++++++++++++----- src/checks.cc | 6 ++--- src/messages.js | 2 ++ src/runtime.js | 2 +- test/mjsunit/regress/regress-57.js | 5 +++++ 8 files changed, 102 insertions(+), 29 deletions(-) create mode 100644 test/mjsunit/regress/regress-57.js diff --git a/include/v8.h b/include/v8.h index c72bb2e..430165a 100644 --- a/include/v8.h +++ b/include/v8.h @@ -880,6 +880,21 @@ class EXPORT String : public Primitive { static Local NewUndetectable(const uint16_t* data, int length = -1); /** + * Converts an object to a utf8-encoded character array. Useful if + * you want to print the object. + */ + class EXPORT Utf8Value { + public: + explicit Utf8Value(Handle obj); + ~Utf8Value(); + char* operator*() { return str_; } + int length() { return length_; } + private: + char* str_; + int length_; + }; + + /** * Converts an object to an ascii string. * Useful if you want to print the object. */ @@ -888,8 +903,10 @@ class EXPORT String : public Primitive { explicit AsciiValue(Handle obj); ~AsciiValue(); char* operator*() { return str_; } + int length() { return length_; } private: char* str_; + int length_; }; /** @@ -900,8 +917,10 @@ class EXPORT String : public Primitive { explicit Value(Handle obj); ~Value(); uint16_t* operator*() { return str_; } + int length() { return length_; } private: uint16_t* str_; + int length_; }; }; diff --git a/samples/process.cc b/samples/process.cc index 57710b3..6567f08 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -137,7 +137,7 @@ static Handle LogCallback(const Arguments& args) { if (args.Length() < 1) return v8::Undefined(); HandleScope scope; Handle arg = args[0]; - String::AsciiValue value(arg); + String::Utf8Value value(arg); HttpRequestProcessor::Log(*value); return v8::Undefined(); } @@ -206,7 +206,7 @@ bool JsHttpRequestProcessor::ExecuteScript(Handle script) { // Compile the script and check for errors. Handle