| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 81d3de7 commit 74954ce
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,6 +62,7 @@ set(node_sources | |||
| 62 | 62 | src/node_script.cc | |
| 63 | 63 | src/node_os.cc | |
| 64 | 64 | src/node_dtrace.cc | |
| 65 | + src/node_string.cc | ||
| 65 | 66 | src/node_natives.h | |
| 66 | 67 | ${node_extra_src}) | |
| 67 | 68 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,6 +48,7 @@ | |||
| 48 | 48 | #include <node_stdio.h> | |
| 49 | 49 | #include <node_javascript.h> | |
| 50 | 50 | #include <node_version.h> | |
| 51 | + #include <node_string.h> | ||
| 51 | 52 | #ifdef HAVE_OPENSSL | |
| 52 | 53 | # include <node_crypto.h> | |
| 53 | 54 | #endif | |
@@ -1269,7 +1270,7 @@ static void ReportException(TryCatch &try_catch, bool show_line) { | |||
| 1269 | 1270 | } | |
| 1270 | 1271 | ||
| 1271 | 1272 | // Executes a str within the current v8 context. | |
| 1272 | - Local<Value> ExecuteString(Local<String> source, Local<Value> filename) { | ||
| 1273 | + Local<Value> ExecuteString(Handle<String> source, Handle<Value> filename) { | ||
| 1273 | 1274 | HandleScope scope; | |
| 1274 | 1275 | TryCatch try_catch; | |
| 1275 | 1276 | ||
@@ -2036,8 +2037,8 @@ static void Load(int argc, char *argv[]) { | |||
| 2036 | 2037 | ||
| 2037 | 2038 | TryCatch try_catch; | |
| 2038 | 2039 | ||
| 2039 | - Local<Value> f_value = ExecuteString(String::New(MainSource()), | ||
| 2040 | - String::New("node.js")); | ||
| 2040 | + Local<Value> f_value = ExecuteString(MainSource(), | ||
| 2041 | + IMMUTABLE_STRING("node.js")); | ||
| 2041 | 2042 | if (try_catch.HasCaught()) { | |
| 2042 | 2043 | ReportException(try_catch, true); | |
| 2043 | 2044 | exit(10); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,16 @@ | |||
| 1 | 1 | #include <v8.h> | |
| 2 | 2 | #include "node.h" | |
| 3 | 3 | #include "node_natives.h" | |
| 4 | + #include "node_string.h" | ||
| 4 | 5 | #include <string.h> | |
| 5 | 6 | #include <strings.h> | |
| 6 | 7 | ||
| 7 | 8 | using namespace v8; | |
| 8 | 9 | ||
| 9 | 10 | namespace node { | |
| 10 | 11 | ||
| 11 | - const char* MainSource() { | ||
| 12 | - return node_native; | ||
| 12 | + Handle<String> MainSource() { | ||
| 13 | + return BUILTIN_ASCII_ARRAY(node_native, sizeof(node_native)-1); | ||
| 13 | 14 | } | |
| 14 | 15 | ||
| 15 | 16 | void DefineJavaScript(v8::Handle<v8::Object> target) { | |
@@ -18,14 +19,10 @@ void DefineJavaScript(v8::Handle<v8::Object> target) { | |||
| 18 | 19 | for (int i = 0; natives[i].name; i++) { | |
| 19 | 20 | if (natives[i].source != node_native) { | |
| 20 | 21 | Local<String> name = String::New(natives[i].name); | |
| 21 | - // TODO: Use ExternalAsciiStringResource for source | ||
| 22 | - // Might need to do some assertions in js2c about chars > 128 | ||
| 23 | - Local<String> source = String::New(natives[i].source); | ||
| 22 | + Handle<String> source = BUILTIN_ASCII_ARRAY(natives[i].source, natives[i].source_len); | ||
| 24 | 23 | target->Set(name, source); | |
| 25 | 24 | } | |
| 26 | 25 | } | |
| 27 | 26 | } | |
| 28 | 27 | ||
| 29 | - | ||
| 30 | - | ||
| 31 | 28 | } // namespace node | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,6 @@ | |||
| 3 | 3 | namespace node { | |
| 4 | 4 | ||
| 5 | 5 | void DefineJavaScript(v8::Handle<v8::Object> target); | |
| 6 | - const char* MainSource(); | ||
| 6 | + v8::Handle<v8::String> MainSource(); | ||
| 7 | 7 | ||
| 8 | 8 | } // namespace node | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + #include "node_string.h" | ||
| 2 | + | ||
| 3 | + namespace node { | ||
| 4 | + | ||
| 5 | + using namespace v8; | ||
| 6 | + | ||
| 7 | + Handle<String> ImmutableAsciiSource::CreateFromLiteral( | ||
| 8 | + const char *string_literal, | ||
| 9 | + size_t length) { | ||
| 10 | + HandleScope scope; | ||
| 11 | + | ||
| 12 | + Local<String> ret = String::NewExternal(new ImmutableAsciiSource( | ||
| 13 | + string_literal, | ||
| 14 | + length)); | ||
| 15 | + return scope.Close(ret); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,42 @@ | |||
| 1 | + #ifndef SRC_NODE_STRING_H_ | ||
| 2 | + #define SRC_NODE_STRING_H_ | ||
| 3 | + | ||
| 4 | + #include <v8.h> | ||
| 5 | + | ||
| 6 | + namespace node { | ||
| 7 | + | ||
| 8 | + #define IMMUTABLE_STRING(string_literal) \ | ||
| 9 | + ::node::ImmutableAsciiSource::CreateFromLiteral( \ | ||
| 10 | + string_literal "", sizeof(string_literal) - 1) | ||
| 11 | + #define BUILTIN_ASCII_ARRAY(array, len) \ | ||
| 12 | + ::node::ImmutableAsciiSource::CreateFromLiteral(array, len) | ||
| 13 | + | ||
| 14 | + class ImmutableAsciiSource : public v8::String::ExternalAsciiStringResource { | ||
| 15 | + public: | ||
| 16 | + static v8::Handle<v8::String> CreateFromLiteral(const char *string_literal, | ||
| 17 | + size_t length); | ||
| 18 | + | ||
| 19 | + ImmutableAsciiSource(const char *src, size_t src_len) | ||
| 20 | + : buffer_(src), | ||
| 21 | + buf_len_(src_len) { | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + ~ImmutableAsciiSource() { | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + const char *data() const { | ||
| 28 | + return buffer_; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + size_t length() const { | ||
| 32 | + return buf_len_; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + private: | ||
| 36 | + const char *buffer_; | ||
| 37 | + size_t buf_len_; | ||
| 38 | + }; | ||
| 39 | + | ||
| 40 | + } // namespace node | ||
| 41 | + | ||
| 42 | + #endif // SRC_NODE_STRING_H_ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,7 +53,7 @@ def ToCArray(filename, lines): | |||
| 53 | 53 | ||
| 54 | 54 | value = ord(chr) | |
| 55 | 55 | ||
| 56 | - if value > 128: | ||
| 56 | + if value >= 128: | ||
| 57 | 57 | print 'non-ascii value ' + filename + ':' + str(row) + ':' + str(col) | |
| 58 | 58 | sys.exit(1); | |
| 59 | 59 | ||
@@ -220,6 +220,7 @@ def ReadMacros(lines): | |||
| 220 | 220 | struct _native { | |
| 221 | 221 | const char* name; | |
| 222 | 222 | const char* source; | |
| 223 | + size_t source_len; | ||
| 223 | 224 | }; | |
| 224 | 225 | ||
| 225 | 226 | static const struct _native natives[] = { | |
@@ -236,7 +237,7 @@ def ReadMacros(lines): | |||
| 236 | 237 | ||
| 237 | 238 | ||
| 238 | 239 | NATIVE_DECLARATION = """\ | |
| 239 | - { "%(id)s", %(id)s_native }, | ||
| 240 | + { "%(id)s", %(id)s_native, sizeof(%(id)s_native)-1 }, | ||
| 240 | 241 | """ | |
| 241 | 242 | ||
| 242 | 243 | SOURCE_DECLARATION = """\ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -801,6 +801,7 @@ def build(bld): | |||
| 801 | 801 | src/node_script.cc | |
| 802 | 802 | src/node_os.cc | |
| 803 | 803 | src/node_dtrace.cc | |
| 804 | + src/node_string.cc | ||
| 804 | 805 | """ | |
| 805 | 806 | ||
| 806 | 807 | if sys.platform.startswith("win32"): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments