OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "include/v8stdint.h" | 5 #include "include/v8stdint.h" |
6 #include "src/base/logging.h" | 6 #include "src/base/logging.h" |
| 7 #include "src/compiler.h" |
7 #include "src/globals.h" | 8 #include "src/globals.h" |
8 #include "src/hashmap.h" | 9 #include "src/hashmap.h" |
9 #include "src/preparse-data.h" | 10 #include "src/preparse-data.h" |
10 #include "src/preparse-data-format.h" | 11 #include "src/preparse-data-format.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 | 16 |
16 CompleteParserRecorder::CompleteParserRecorder() | 17 CompleteParserRecorder::CompleteParserRecorder() |
(...skipping 10 matching lines...) Expand all Loading... |
27 prev_start_ = -1; | 28 prev_start_ = -1; |
28 #endif | 29 #endif |
29 } | 30 } |
30 | 31 |
31 | 32 |
32 void CompleteParserRecorder::LogMessage(int start_pos, | 33 void CompleteParserRecorder::LogMessage(int start_pos, |
33 int end_pos, | 34 int end_pos, |
34 const char* message, | 35 const char* message, |
35 const char* arg_opt, | 36 const char* arg_opt, |
36 bool is_reference_error) { | 37 bool is_reference_error) { |
37 if (has_error()) return; | 38 if (HasError()) return; |
38 preamble_[PreparseDataConstants::kHasErrorOffset] = true; | 39 preamble_[PreparseDataConstants::kHasErrorOffset] = true; |
39 function_store_.Reset(); | 40 function_store_.Reset(); |
40 STATIC_ASSERT(PreparseDataConstants::kMessageStartPos == 0); | 41 STATIC_ASSERT(PreparseDataConstants::kMessageStartPos == 0); |
41 function_store_.Add(start_pos); | 42 function_store_.Add(start_pos); |
42 STATIC_ASSERT(PreparseDataConstants::kMessageEndPos == 1); | 43 STATIC_ASSERT(PreparseDataConstants::kMessageEndPos == 1); |
43 function_store_.Add(end_pos); | 44 function_store_.Add(end_pos); |
44 STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2); | 45 STATIC_ASSERT(PreparseDataConstants::kMessageArgCountPos == 2); |
45 function_store_.Add((arg_opt == NULL) ? 0 : 1); | 46 function_store_.Add((arg_opt == NULL) ? 0 : 1); |
46 STATIC_ASSERT(PreparseDataConstants::kIsReferenceErrorPos == 3); | 47 STATIC_ASSERT(PreparseDataConstants::kIsReferenceErrorPos == 3); |
47 function_store_.Add(is_reference_error ? 1 : 0); | 48 function_store_.Add(is_reference_error ? 1 : 0); |
48 STATIC_ASSERT(PreparseDataConstants::kMessageTextPos == 4); | 49 STATIC_ASSERT(PreparseDataConstants::kMessageTextPos == 4); |
49 WriteString(CStrVector(message)); | 50 WriteString(CStrVector(message)); |
50 if (arg_opt != NULL) WriteString(CStrVector(arg_opt)); | 51 if (arg_opt != NULL) WriteString(CStrVector(arg_opt)); |
51 } | 52 } |
52 | 53 |
53 | 54 |
54 void CompleteParserRecorder::WriteString(Vector<const char> str) { | 55 void CompleteParserRecorder::WriteString(Vector<const char> str) { |
55 function_store_.Add(str.length()); | 56 function_store_.Add(str.length()); |
56 for (int i = 0; i < str.length(); i++) { | 57 for (int i = 0; i < str.length(); i++) { |
57 function_store_.Add(str[i]); | 58 function_store_.Add(str[i]); |
58 } | 59 } |
59 } | 60 } |
60 | 61 |
61 | 62 |
62 Vector<unsigned> CompleteParserRecorder::ExtractData() { | 63 ScriptData* CompleteParserRecorder::GetScriptData() { |
63 int function_size = function_store_.size(); | 64 int function_size = function_store_.size(); |
64 int total_size = PreparseDataConstants::kHeaderSize + function_size; | 65 int total_size = PreparseDataConstants::kHeaderSize + function_size; |
65 Vector<unsigned> data = Vector<unsigned>::New(total_size); | 66 unsigned* data = NewArray<unsigned>(total_size); |
66 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size; | 67 preamble_[PreparseDataConstants::kFunctionsSizeOffset] = function_size; |
67 MemCopy(data.start(), preamble_, sizeof(preamble_)); | 68 MemCopy(data, preamble_, sizeof(preamble_)); |
68 if (function_size > 0) { | 69 if (function_size > 0) { |
69 function_store_.WriteTo(data.SubVector(PreparseDataConstants::kHeaderSize, | 70 function_store_.WriteTo(Vector<unsigned>( |
70 total_size)); | 71 data + PreparseDataConstants::kHeaderSize, function_size)); |
71 } | 72 } |
72 return data; | 73 ASSERT(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); |
| 74 ScriptData* result = new ScriptData(reinterpret_cast<byte*>(data), |
| 75 total_size * sizeof(unsigned)); |
| 76 result->AcquireDataOwnership(); |
| 77 return result; |
73 } | 78 } |
74 | 79 |
75 | 80 |
76 } } // namespace v8::internal. | 81 } } // namespace v8::internal. |
OLD | NEW |