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

Side by Side Diff: src/handles.cc

Issue 18707: Split handle scopes into an internal version and a version accessible... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 11 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
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 22 matching lines...) Expand all
33 #include "compiler.h" 33 #include "compiler.h"
34 #include "debug.h" 34 #include "debug.h"
35 #include "execution.h" 35 #include "execution.h"
36 #include "global-handles.h" 36 #include "global-handles.h"
37 #include "natives.h" 37 #include "natives.h"
38 #include "runtime.h" 38 #include "runtime.h"
39 39
40 namespace v8 { namespace internal { 40 namespace v8 { namespace internal {
41 41
42 42
43 v8::ImplementationUtilities::HandleScopeData HandleScope::current_ =
44 { -1, NULL, NULL };
45
46
47 int HandleScope::NumberOfHandles() {
48 int n = HandleScopeImplementer::instance()->Blocks()->length();
49 if (n == 0) return 0;
50 return ((n - 1) * kHandleBlockSize) +
51 (current_.next - HandleScopeImplementer::instance()->Blocks()->last());
52 }
53
54
55 void** HandleScope::CreateHandle(void* value) {
56 void** result = current_.next;
57 if (result == current_.limit) {
58 // Make sure there's at least one scope on the stack and that the
59 // top of the scope stack isn't a barrier.
60 if (current_.extensions < 0) {
61 Utils::ReportApiFailure("v8::HandleScope::CreateHandle()",
62 "Cannot create a handle without a HandleScope");
63 return NULL;
64 }
65 HandleScopeImplementer* impl = HandleScopeImplementer::instance();
66 // If there's more room in the last block, we use that. This is used
67 // for fast creation of scopes after scope barriers.
68 if (!impl->Blocks()->is_empty()) {
69 void** limit = &impl->Blocks()->last()[kHandleBlockSize];
70 if (current_.limit != limit) {
71 current_.limit = limit;
72 }
73 }
74
75 // If we still haven't found a slot for the handle, we extend the
76 // current handle scope by allocating a new handle block.
77 if (result == current_.limit) {
78 // If there's a spare block, use it for growing the current scope.
79 result = impl->GetSpareOrNewBlock();
80 // Add the extension to the global list of blocks, but count the
81 // extension as part of the current scope.
82 impl->Blocks()->Add(result);
83 current_.extensions++;
84 current_.limit = &result[kHandleBlockSize];
85 }
86 }
87
88 // Update the current next field, set the value in the created
89 // handle, and return the result.
90 ASSERT(result < current_.limit);
91 current_.next = result + 1;
92 *result = value;
93 return result;
94 }
95
96
97 void HandleScope::DeleteExtensions() {
98 ASSERT(current_.extensions != 0);
99 HandleScopeImplementer::instance()->DeleteExtensions(current_.extensions);
100 }
101
102
103 void HandleScope::ZapRange(void** start, void** end) {
104 if (start == NULL) return;
105 for (void** p = start; p < end; p++) {
106 *p = reinterpret_cast<void*>(v8::internal::kHandleZapValue);
107 }
108 }
109
110
43 Handle<FixedArray> AddKeysFromJSArray(Handle<FixedArray> content, 111 Handle<FixedArray> AddKeysFromJSArray(Handle<FixedArray> content,
44 Handle<JSArray> array) { 112 Handle<JSArray> array) {
45 CALL_HEAP_FUNCTION(content->AddKeysFromJSArray(*array), FixedArray); 113 CALL_HEAP_FUNCTION(content->AddKeysFromJSArray(*array), FixedArray);
46 } 114 }
47 115
48 116
49 Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first, 117 Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
50 Handle<FixedArray> second) { 118 Handle<FixedArray> second) {
51 CALL_HEAP_FUNCTION(first->UnionOfKeys(*second), FixedArray); 119 CALL_HEAP_FUNCTION(first->UnionOfKeys(*second), FixedArray);
52 } 120 }
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 Handle<Context> compile_context, 603 Handle<Context> compile_context,
536 Handle<Context> function_context) { 604 Handle<Context> function_context) {
537 Handle<FixedArray> arr = Factory::NewFixedArray(3); 605 Handle<FixedArray> arr = Factory::NewFixedArray(3);
538 arr->set(0, Smi::FromInt(index)); 606 arr->set(0, Smi::FromInt(index));
539 arr->set(1, *compile_context); // Compile in this context 607 arr->set(1, *compile_context); // Compile in this context
540 arr->set(2, *function_context); // Set function context to this 608 arr->set(2, *function_context); // Set function context to this
541 fun->shared()->set_lazy_load_data(*arr); 609 fun->shared()->set_lazy_load_data(*arr);
542 } 610 }
543 611
544 } } // namespace v8::internal 612 } } // namespace v8::internal
OLDNEW
« src/apiutils.h ('K') | « src/handles.h ('k') | src/handles-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698