Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1027)

Side by Side Diff: src/handles.cc

Issue 43020: Move InitLineEnds and GetLineNumber to handles.cc to avoid... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/handles.h ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 180
181 void TransformToFastProperties(Handle<JSObject> object, 181 void TransformToFastProperties(Handle<JSObject> object,
182 int unused_property_fields) { 182 int unused_property_fields) {
183 CALL_HEAP_FUNCTION_VOID( 183 CALL_HEAP_FUNCTION_VOID(
184 object->TransformToFastProperties(unused_property_fields)); 184 object->TransformToFastProperties(unused_property_fields));
185 } 185 }
186 186
187 187
188 void FlattenString(Handle<String> string) { 188 void FlattenString(Handle<String> string) {
189 StringShape shape(*string); 189 CALL_HEAP_FUNCTION_VOID(string->TryFlattenIfNotFlat(StringShape(*string)));
Mads Ager (chromium) 2009/03/10 19:26:58 I think this change makes the code much clearer (a
190 if (string->IsFlat(shape)) return;
191 CALL_HEAP_FUNCTION_VOID(string->TryFlatten(shape));
192 ASSERT(string->IsFlat(StringShape(*string))); 190 ASSERT(string->IsFlat(StringShape(*string)));
193 } 191 }
194 192
195 193
196 Handle<Object> SetPrototype(Handle<JSFunction> function, 194 Handle<Object> SetPrototype(Handle<JSFunction> function,
197 Handle<Object> prototype) { 195 Handle<Object> prototype) {
198 CALL_HEAP_FUNCTION(Accessors::FunctionSetPrototype(*function, 196 CALL_HEAP_FUNCTION(Accessors::FunctionSetPrototype(*function,
199 *prototype, 197 *prototype,
200 NULL), 198 NULL),
201 Object); 199 Object);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // Create a new weak global handle and use it to cache the wrapper 334 // Create a new weak global handle and use it to cache the wrapper
337 // for future use. The cache will automatically be cleared by the 335 // for future use. The cache will automatically be cleared by the
338 // garbage collector when it is not used anymore. 336 // garbage collector when it is not used anymore.
339 Handle<Object> handle = GlobalHandles::Create(*result); 337 Handle<Object> handle = GlobalHandles::Create(*result);
340 GlobalHandles::MakeWeak(handle.location(), NULL, &ClearWrapperCache); 338 GlobalHandles::MakeWeak(handle.location(), NULL, &ClearWrapperCache);
341 script->wrapper()->set_proxy(reinterpret_cast<Address>(handle.location())); 339 script->wrapper()->set_proxy(reinterpret_cast<Address>(handle.location()));
342 return result; 340 return result;
343 } 341 }
344 342
345 343
344 // Init line_ends array with code positions of line ends inside script
345 // source.
346 void InitScriptLineEnds(Handle<Script> script) {
347 if (!script->line_ends()->IsUndefined()) return;
348
349 if (!script->source()->IsString()) {
350 ASSERT(script->source()->IsUndefined());
351 script->set_line_ends(*(Factory::NewJSArray(0)));
352 ASSERT(script->line_ends()->IsJSArray());
353 return;
354 }
355
356 Handle<String> src(String::cast(script->source()));
357 const int src_len = src->length();
358 Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n"));
359
360 // Pass 1: Identify line count.
361 int line_count = 0;
362 int position = 0;
363 while (position != -1 && position < src_len) {
364 position = Runtime::StringMatch(src, new_line, position);
365 if (position != -1) {
366 position++;
367 }
368 // Even if the last line misses a line end, it is counted.
369 line_count++;
370 }
371
372 // Pass 2: Fill in line ends positions
373 Handle<FixedArray> array = Factory::NewFixedArray(line_count);
374 int array_index = 0;
375 position = 0;
376 while (position != -1 && position < src_len) {
377 position = Runtime::StringMatch(src, new_line, position);
378 // If the script does not end with a line ending add the final end
379 // position as just past the last line ending.
380 array->set(array_index++,
381 Smi::FromInt(position != -1 ? position++ : src_len));
382 }
383 ASSERT(array_index == line_count);
384
385 Handle<JSArray> object = Factory::NewJSArrayWithElements(array);
386 script->set_line_ends(*object);
387 ASSERT(script->line_ends()->IsJSArray());
388 }
389
390
391 // Convert code position into line number.
392 int GetScriptLineNumber(Handle<Script> script, int code_pos) {
393 InitScriptLineEnds(script);
394 AssertNoAllocation no_allocation;
395 JSArray* line_ends_array = JSArray::cast(script->line_ends());
396 const int line_ends_len = (Smi::cast(line_ends_array->length()))->value();
397
398 int line = -1;
399 if (line_ends_len > 0 &&
400 code_pos <= (Smi::cast(line_ends_array->GetElement(0)))->value()) {
401 line = 0;
402 } else {
403 for (int i = 1; i < line_ends_len; ++i) {
404 if ((Smi::cast(line_ends_array->GetElement(i - 1)))->value() < code_pos &&
405 code_pos <= (Smi::cast(line_ends_array->GetElement(i)))->value()) {
406 line = i;
407 break;
408 }
409 }
410 }
411
412 return line != -1 ? line + script->line_offset()->value() : line;
413 }
414
415
346 // Compute the property keys from the interceptor. 416 // Compute the property keys from the interceptor.
347 v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSObject> receiver, 417 v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSObject> receiver,
348 Handle<JSObject> object) { 418 Handle<JSObject> object) {
349 Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor()); 419 Handle<InterceptorInfo> interceptor(object->GetNamedInterceptor());
350 Handle<Object> data(interceptor->data()); 420 Handle<Object> data(interceptor->data());
351 v8::AccessorInfo info( 421 v8::AccessorInfo info(
352 v8::Utils::ToLocal(receiver), 422 v8::Utils::ToLocal(receiver),
353 v8::Utils::ToLocal(data), 423 v8::Utils::ToLocal(data),
354 v8::Utils::ToLocal(object)); 424 v8::Utils::ToLocal(object));
355 v8::Handle<v8::Array> result; 425 v8::Handle<v8::Array> result;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 Handle<Context> compile_context, 673 Handle<Context> compile_context,
604 Handle<Context> function_context) { 674 Handle<Context> function_context) {
605 Handle<FixedArray> arr = Factory::NewFixedArray(3); 675 Handle<FixedArray> arr = Factory::NewFixedArray(3);
606 arr->set(0, Smi::FromInt(index)); 676 arr->set(0, Smi::FromInt(index));
607 arr->set(1, *compile_context); // Compile in this context 677 arr->set(1, *compile_context); // Compile in this context
608 arr->set(2, *function_context); // Set function context to this 678 arr->set(2, *function_context); // Set function context to this
609 fun->shared()->set_lazy_load_data(*arr); 679 fun->shared()->set_lazy_load_data(*arr);
610 } 680 }
611 681
612 } } // namespace v8::internal 682 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/handles.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698