blob: e4962ef38e4e671548727c7c76a06e81a3019c76 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29
30#include "accessors.h"
31#include "api.h"
32#include "bootstrapper.h"
33#include "compiler.h"
34#include "debug.h"
35#include "execution.h"
36#include "global-handles.h"
37#include "macro-assembler.h"
38#include "natives.h"
39
40namespace v8 { namespace internal {
41
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000042// A SourceCodeCache uses a FixedArray to store pairs of
43// (AsciiString*, JSFunction*), mapping names of native code files
44// (runtime.js, etc.) to precompiled functions. Instead of mapping
45// names to functions it might make sense to let the JS2C tool
46// generate an index for each native JS file.
47class SourceCodeCache BASE_EMBEDDED {
48 public:
49 explicit SourceCodeCache(ScriptType type): type_(type) { }
50
51 void Initialize(bool create_heap_objects) {
52 if (create_heap_objects) {
53 cache_ = Heap::empty_fixed_array();
54 } else {
55 cache_ = NULL;
56 }
57 }
58
59 void Iterate(ObjectVisitor* v) {
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000060 v->VisitPointer(bit_cast<Object**, FixedArray**>(&cache_));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000061 }
62
63
64 bool Lookup(Vector<const char> name, Handle<JSFunction>* handle) {
65 for (int i = 0; i < cache_->length(); i+=2) {
ager@chromium.org7c537e22008-10-16 08:43:32 +000066 SeqAsciiString* str = SeqAsciiString::cast(cache_->get(i));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000067 if (str->IsEqualTo(name)) {
68 *handle = Handle<JSFunction>(JSFunction::cast(cache_->get(i + 1)));
69 return true;
70 }
71 }
72 return false;
73 }
74
75
76 void Add(Vector<const char> name, Handle<JSFunction> fun) {
77 ASSERT(fun->IsBoilerplate());
78 HandleScope scope;
79 int length = cache_->length();
80 Handle<FixedArray> new_array =
81 Factory::NewFixedArray(length + 2, TENURED);
82 cache_->CopyTo(0, *new_array, 0, cache_->length());
83 cache_ = *new_array;
84 Handle<String> str = Factory::NewStringFromAscii(name, TENURED);
85 cache_->set(length, *str);
86 cache_->set(length + 1, *fun);
87 Script::cast(fun->shared()->script())->set_type(Smi::FromInt(type_));
88 }
89
90 private:
91 ScriptType type_;
92 FixedArray* cache_;
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +000093 DISALLOW_COPY_AND_ASSIGN(SourceCodeCache);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000094};
95
96static SourceCodeCache natives_cache(SCRIPT_TYPE_NATIVE);
97static SourceCodeCache extensions_cache(SCRIPT_TYPE_EXTENSION);
98
99
100Handle<String> Bootstrapper::NativesSourceLookup(int index) {
101 ASSERT(0 <= index && index < Natives::GetBuiltinsCount());
102 if (Heap::natives_source_cache()->get(index)->IsUndefined()) {
103 Handle<String> source_code =
104 Factory::NewStringFromAscii(Natives::GetScriptSource(index));
105 Heap::natives_source_cache()->set(index, *source_code);
106 }
107 Handle<Object> cached_source(Heap::natives_source_cache()->get(index));
108 return Handle<String>::cast(cached_source);
109}
110
111
112bool Bootstrapper::NativesCacheLookup(Vector<const char> name,
113 Handle<JSFunction>* handle) {
114 return natives_cache.Lookup(name, handle);
115}
116
117
118void Bootstrapper::NativesCacheAdd(Vector<const char> name,
119 Handle<JSFunction> fun) {
120 natives_cache.Add(name, fun);
121}
122
123
124void Bootstrapper::Initialize(bool create_heap_objects) {
125 natives_cache.Initialize(create_heap_objects);
126 extensions_cache.Initialize(create_heap_objects);
127}
128
129
130void Bootstrapper::TearDown() {
131 natives_cache.Initialize(false); // Yes, symmetrical
132 extensions_cache.Initialize(false);
133}
134
135
136// Pending fixups are code positions that have refer to builtin code
137// objects that were not available at the time the code was generated.
138// The pending list is processed whenever an environment has been
139// created.
140class PendingFixups : public AllStatic {
141 public:
142 static void Add(Code* code, MacroAssembler* masm);
143 static bool Process(Handle<JSBuiltinsObject> builtins);
144
145 static void Iterate(ObjectVisitor* v);
146
147 private:
148 static List<Object*> code_;
149 static List<const char*> name_;
150 static List<int> pc_;
151 static List<uint32_t> flags_;
152
153 static void Clear();
154};
155
156
157List<Object*> PendingFixups::code_(0);
158List<const char*> PendingFixups::name_(0);
159List<int> PendingFixups::pc_(0);
160List<uint32_t> PendingFixups::flags_(0);
161
162
163void PendingFixups::Add(Code* code, MacroAssembler* masm) {
164 // Note this code is not only called during bootstrapping.
165 List<MacroAssembler::Unresolved>* unresolved = masm->unresolved();
166 int n = unresolved->length();
167 for (int i = 0; i < n; i++) {
168 const char* name = unresolved->at(i).name;
169 code_.Add(code);
170 name_.Add(name);
171 pc_.Add(unresolved->at(i).pc);
172 flags_.Add(unresolved->at(i).flags);
173 LOG(StringEvent("unresolved", name));
174 }
175}
176
177
178bool PendingFixups::Process(Handle<JSBuiltinsObject> builtins) {
179 HandleScope scope;
180 // NOTE: Extra fixups may be added to the list during the iteration
181 // due to lazy compilation of functions during the processing. Do not
182 // cache the result of getting the length of the code list.
183 for (int i = 0; i < code_.length(); i++) {
184 const char* name = name_[i];
185 uint32_t flags = flags_[i];
186 Handle<String> symbol = Factory::LookupAsciiSymbol(name);
187 Object* o = builtins->GetProperty(*symbol);
188#ifdef DEBUG
189 if (!o->IsJSFunction()) {
190 V8_Fatal(__FILE__, __LINE__, "Cannot resolve call to builtin %s", name);
191 }
192#endif
193 Handle<JSFunction> f = Handle<JSFunction>(JSFunction::cast(o));
194 // Make sure the number of parameters match the formal parameter count.
195 int argc = Bootstrapper::FixupFlagsArgumentsCount::decode(flags);
196 USE(argc);
197 ASSERT(f->shared()->formal_parameter_count() == argc);
198 if (!f->is_compiled()) {
199 // Do lazy compilation and check for stack overflows.
200 if (!CompileLazy(f, CLEAR_EXCEPTION)) {
201 Clear();
202 return false;
203 }
204 }
205 Code* code = Code::cast(code_[i]);
206 Address pc = code->instruction_start() + pc_[i];
207 bool is_pc_relative = Bootstrapper::FixupFlagsIsPCRelative::decode(flags);
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000208 bool use_code_object = Bootstrapper::FixupFlagsUseCodeObject::decode(flags);
209
210 if (use_code_object) {
211 if (is_pc_relative) {
212 Assembler::set_target_address_at(
213 pc, reinterpret_cast<Address>(f->code()));
214 } else {
215 *reinterpret_cast<Object**>(pc) = f->code();
216 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000217 } else {
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000218 ASSERT(is_pc_relative);
219 Assembler::set_target_address_at(pc, f->code()->instruction_start());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000220 }
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000221
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000222 LOG(StringEvent("resolved", name));
223 }
224 Clear();
225
226 // TODO(1240818): We should probably try to avoid doing this for all
227 // the V8 builtin JS files. It should only happen after running
228 // runtime.js - just like there shouldn't be any fixups left after
229 // that.
230 for (int i = 0; i < Builtins::NumberOfJavaScriptBuiltins(); i++) {
231 Builtins::JavaScript id = static_cast<Builtins::JavaScript>(i);
232 Handle<String> name = Factory::LookupAsciiSymbol(Builtins::GetName(id));
233 JSFunction* function = JSFunction::cast(builtins->GetProperty(*name));
234 builtins->set_javascript_builtin(id, function);
235 }
236
237 return true;
238}
239
240
241void PendingFixups::Clear() {
242 code_.Clear();
243 name_.Clear();
244 pc_.Clear();
245 flags_.Clear();
246}
247
248
249void PendingFixups::Iterate(ObjectVisitor* v) {
250 if (!code_.is_empty()) {
251 v->VisitPointers(&code_[0], &code_[0] + code_.length());
252 }
253}
254
255
256class Genesis BASE_EMBEDDED {
257 public:
258 Genesis(Handle<Object> global_object,
259 v8::Handle<v8::ObjectTemplate> global_template,
260 v8::ExtensionConfiguration* extensions);
261 ~Genesis();
262
263 Handle<Context> result() { return result_; }
264
265 Genesis* previous() { return previous_; }
266 static Genesis* current() { return current_; }
267
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000268 // Support for thread preemption.
269 static int ArchiveSpacePerThread();
270 static char* ArchiveState(char* to);
271 static char* RestoreState(char* from);
272
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000273 private:
274 Handle<Context> global_context_;
275
276 // There may be more than one active genesis object: When GC is
277 // triggered during environment creation there may be weak handle
278 // processing callbacks which may create new environments.
279 Genesis* previous_;
280 static Genesis* current_;
281
282 Handle<Context> global_context() { return global_context_; }
283
284 void CreateRoots(v8::Handle<v8::ObjectTemplate> global_template,
285 Handle<Object> global_object);
286 void InstallNativeFunctions();
287 bool InstallNatives();
288 bool InstallExtensions(v8::ExtensionConfiguration* extensions);
289 bool InstallExtension(const char* name);
290 bool InstallExtension(v8::RegisteredExtension* current);
mads.s.agercbaa0602008-08-14 13:41:48 +0000291 bool InstallSpecialObjects();
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000292 bool ConfigureApiObject(Handle<JSObject> object,
293 Handle<ObjectTemplateInfo> object_template);
294 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000295
296 // Migrates all properties from the 'from' object to the 'to'
297 // object and overrides the prototype in 'to' with the one from
298 // 'from'.
299 void TransferObject(Handle<JSObject> from, Handle<JSObject> to);
300 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to);
301 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to);
302
303 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor(
304 bool make_prototype_read_only,
305 bool make_prototype_enumerable = false);
306 void MakeFunctionInstancePrototypeWritable();
307
308 void AddSpecialFunction(Handle<JSObject> prototype,
309 const char* name,
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000310 Handle<Code> code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000311
312 void BuildSpecialFunctionTable();
313
314 static bool CompileBuiltin(int index);
315 static bool CompileNative(Vector<const char> name, Handle<String> source);
316 static bool CompileScriptCached(Vector<const char> name,
317 Handle<String> source,
318 SourceCodeCache* cache,
319 v8::Extension* extension,
320 bool use_runtime_context);
321
322 Handle<Context> result_;
323};
324
325Genesis* Genesis::current_ = NULL;
326
327
328void Bootstrapper::Iterate(ObjectVisitor* v) {
329 natives_cache.Iterate(v);
330 extensions_cache.Iterate(v);
331 PendingFixups::Iterate(v);
332}
333
334
335// While setting up the environment, we collect code positions that
336// need to be patched before we can run any code in the environment.
337void Bootstrapper::AddFixup(Code* code, MacroAssembler* masm) {
338 PendingFixups::Add(code, masm);
339}
340
341
342bool Bootstrapper::IsActive() {
343 return Genesis::current() != NULL;
344}
345
346
347Handle<Context> Bootstrapper::CreateEnvironment(
348 Handle<Object> global_object,
349 v8::Handle<v8::ObjectTemplate> global_template,
350 v8::ExtensionConfiguration* extensions) {
351 Genesis genesis(global_object, global_template, extensions);
352 return genesis.result();
353}
354
355
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000356static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) {
357 // object.__proto__ = proto;
358 Handle<Map> old_to_map = Handle<Map>(object->map());
359 Handle<Map> new_to_map = Factory::CopyMapDropTransitions(old_to_map);
360 new_to_map->set_prototype(*proto);
361 object->set_map(*new_to_map);
362}
363
364
365void Bootstrapper::DetachGlobal(Handle<Context> env) {
366 JSGlobalProxy::cast(env->global_proxy())->set_context(*Factory::null_value());
367 SetObjectPrototype(Handle<JSObject>(env->global_proxy()),
368 Factory::null_value());
369 env->set_global_proxy(env->global());
370 env->global()->set_global_receiver(env->global());
371}
372
373
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000374Genesis::~Genesis() {
375 ASSERT(current_ == this);
376 current_ = previous_;
377}
378
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000379
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000380static Handle<JSFunction> InstallFunction(Handle<JSObject> target,
381 const char* name,
382 InstanceType type,
383 int instance_size,
384 Handle<JSObject> prototype,
385 Builtins::Name call,
386 bool is_ecma_native) {
387 Handle<String> symbol = Factory::LookupAsciiSymbol(name);
388 Handle<Code> call_code = Handle<Code>(Builtins::builtin(call));
389 Handle<JSFunction> function =
390 Factory::NewFunctionWithPrototype(symbol,
391 type,
392 instance_size,
393 prototype,
394 call_code,
395 is_ecma_native);
396 SetProperty(target, symbol, function, DONT_ENUM);
397 if (is_ecma_native) {
398 function->shared()->set_instance_class_name(*symbol);
399 }
400 return function;
401}
402
403
404Handle<DescriptorArray> Genesis::ComputeFunctionInstanceDescriptor(
405 bool make_prototype_read_only,
406 bool make_prototype_enumerable) {
407 Handle<DescriptorArray> result = Factory::empty_descriptor_array();
408
409 // Add prototype.
410 PropertyAttributes attributes = static_cast<PropertyAttributes>(
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000411 (make_prototype_enumerable ? 0 : DONT_ENUM)
412 | DONT_DELETE
413 | (make_prototype_read_only ? READ_ONLY : 0));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000414 result =
415 Factory::CopyAppendProxyDescriptor(
416 result,
417 Factory::prototype_symbol(),
418 Factory::NewProxy(&Accessors::FunctionPrototype),
419 attributes);
420
421 attributes =
422 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
423 // Add length.
424 result =
425 Factory::CopyAppendProxyDescriptor(
426 result,
427 Factory::length_symbol(),
428 Factory::NewProxy(&Accessors::FunctionLength),
429 attributes);
430
431 // Add name.
432 result =
433 Factory::CopyAppendProxyDescriptor(
434 result,
435 Factory::name_symbol(),
436 Factory::NewProxy(&Accessors::FunctionName),
437 attributes);
438
439 // Add arguments.
440 result =
441 Factory::CopyAppendProxyDescriptor(
442 result,
443 Factory::arguments_symbol(),
444 Factory::NewProxy(&Accessors::FunctionArguments),
445 attributes);
446
447 // Add caller.
448 result =
449 Factory::CopyAppendProxyDescriptor(
450 result,
451 Factory::caller_symbol(),
452 Factory::NewProxy(&Accessors::FunctionCaller),
453 attributes);
454
455 return result;
456}
457
458
459void Genesis::CreateRoots(v8::Handle<v8::ObjectTemplate> global_template,
460 Handle<Object> global_object) {
461 HandleScope scope;
462 // Allocate the global context FixedArray first and then patch the
463 // closure and extension object later (we need the empty function
464 // and the global object, but in order to create those, we need the
465 // global context).
466 global_context_ =
467 Handle<Context>::cast(
468 GlobalHandles::Create(*Factory::NewGlobalContext()));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000469 Top::set_context(*global_context());
470
471 // Allocate the message listeners object.
472 v8::NeanderArray listeners;
473 global_context()->set_message_listeners(*listeners.value());
474
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000475 // Allocate the map for function instances.
476 Handle<Map> fm = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
477 global_context()->set_function_instance_map(*fm);
478 // Please note that the prototype property for function instances must be
479 // writable.
480 Handle<DescriptorArray> function_map_descriptors =
481 ComputeFunctionInstanceDescriptor(false, true);
482 fm->set_instance_descriptors(*function_map_descriptors);
483
484 // Allocate the function map first and then patch the prototype later
485 fm = Factory::NewMap(JS_FUNCTION_TYPE, JSFunction::kSize);
486 global_context()->set_function_map(*fm);
487 function_map_descriptors = ComputeFunctionInstanceDescriptor(true);
488 fm->set_instance_descriptors(*function_map_descriptors);
489
490 Handle<String> object_name = Handle<String>(Heap::Object_symbol());
491
492 { // --- O b j e c t ---
493 Handle<JSFunction> object_fun =
494 Factory::NewFunction(object_name, Factory::null_value());
495 Handle<Map> object_function_map =
496 Factory::NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
497 object_fun->set_initial_map(*object_function_map);
498 object_function_map->set_constructor(*object_fun);
499
500 global_context()->set_object_function(*object_fun);
501
502 // Allocate a new prototype for the object function.
503 Handle<JSObject> prototype = Factory::NewJSObject(Top::object_function(),
504 TENURED);
505
506 global_context()->set_initial_object_prototype(*prototype);
507 SetPrototype(object_fun, prototype);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000508 object_function_map->
509 set_instance_descriptors(Heap::empty_descriptor_array());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000510 }
511
512 // Allocate the empty function as the prototype for function ECMAScript
513 // 262 15.3.4.
514 Handle<String> symbol = Factory::LookupAsciiSymbol("Empty");
515 Handle<JSFunction> empty_function =
516 Factory::NewFunction(symbol, Factory::null_value());
517
518 { // --- E m p t y ---
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000519 Handle<Code> code =
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000520 Handle<Code>(Builtins::builtin(Builtins::EmptyFunction));
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000521 empty_function->set_code(*code);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000522 Handle<String> source = Factory::NewStringFromAscii(CStrVector("() {}"));
523 Handle<Script> script = Factory::NewScript(source);
524 script->set_type(Smi::FromInt(SCRIPT_TYPE_NATIVE));
525 empty_function->shared()->set_script(*script);
kasper.lund7276f142008-07-30 08:49:36 +0000526 empty_function->shared()->set_start_position(0);
527 empty_function->shared()->set_end_position(source->length());
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000528 empty_function->shared()->DontAdaptArguments();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000529 global_context()->function_map()->set_prototype(*empty_function);
530 global_context()->function_instance_map()->set_prototype(*empty_function);
531
532 // Allocate the function map first and then patch the prototype later
ager@chromium.org3a37e9b2009-04-27 09:26:21 +0000533 Handle<Map> empty_fm = Factory::CopyMapDropDescriptors(fm);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000534 empty_fm->set_instance_descriptors(*function_map_descriptors);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000535 empty_fm->set_prototype(global_context()->object_function()->prototype());
536 empty_function->set_map(*empty_fm);
537 }
538
539 { // --- G l o b a l ---
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000540 // Step 1: create a fresh inner JSGlobalObject
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000541 Handle<JSGlobalObject> object;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000542 {
543 Handle<JSFunction> js_global_function;
544 Handle<ObjectTemplateInfo> js_global_template;
545 if (!global_template.IsEmpty()) {
546 // Get prototype template of the global_template
547 Handle<ObjectTemplateInfo> data =
548 v8::Utils::OpenHandle(*global_template);
549 Handle<FunctionTemplateInfo> global_constructor =
550 Handle<FunctionTemplateInfo>(
551 FunctionTemplateInfo::cast(data->constructor()));
552 Handle<Object> proto_template(global_constructor->prototype_template());
553 if (!proto_template->IsUndefined()) {
554 js_global_template =
555 Handle<ObjectTemplateInfo>::cast(proto_template);
556 }
557 }
558
559 if (js_global_template.is_null()) {
560 Handle<String> name = Handle<String>(Heap::empty_symbol());
561 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));
562 js_global_function =
563 Factory::NewFunction(name, JS_GLOBAL_OBJECT_TYPE,
564 JSGlobalObject::kSize, code, true);
565 // Change the constructor property of the prototype of the
566 // hidden global function to refer to the Object function.
567 Handle<JSObject> prototype =
568 Handle<JSObject>(
569 JSObject::cast(js_global_function->instance_prototype()));
570 SetProperty(prototype, Factory::constructor_symbol(),
571 Top::object_function(), NONE);
572 } else {
573 Handle<FunctionTemplateInfo> js_global_constructor(
574 FunctionTemplateInfo::cast(js_global_template->constructor()));
575 js_global_function =
576 Factory::CreateApiFunction(js_global_constructor,
577 Factory::InnerGlobalObject);
578 }
579
580 js_global_function->initial_map()->set_is_hidden_prototype();
581 SetExpectedNofProperties(js_global_function, 100);
582 object = Handle<JSGlobalObject>::cast(
583 Factory::NewJSObject(js_global_function, TENURED));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000584 }
585
586 // Set the global context for the global object.
587 object->set_global_context(*global_context());
588
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000589 // Step 2: create or re-initialize the global proxy object.
590 Handle<JSGlobalProxy> global_proxy;
591 {
592 Handle<JSFunction> global_proxy_function;
593 if (global_template.IsEmpty()) {
594 Handle<String> name = Handle<String>(Heap::empty_symbol());
595 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));
596 global_proxy_function =
597 Factory::NewFunction(name, JS_GLOBAL_PROXY_TYPE,
598 JSGlobalProxy::kSize, code, true);
599 } else {
600 Handle<ObjectTemplateInfo> data =
601 v8::Utils::OpenHandle(*global_template);
602 Handle<FunctionTemplateInfo> global_constructor(
603 FunctionTemplateInfo::cast(data->constructor()));
604 global_proxy_function =
605 Factory::CreateApiFunction(global_constructor,
606 Factory::OuterGlobalObject);
607 }
608
609 Handle<String> global_name = Factory::LookupAsciiSymbol("global");
610 global_proxy_function->shared()->set_instance_class_name(*global_name);
ager@chromium.org870a0b62008-11-04 11:43:05 +0000611 global_proxy_function->initial_map()->set_is_access_check_needed(true);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000612
613 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects
614
615 if (global_object.location() != NULL) {
616 ASSERT(global_object->IsJSGlobalProxy());
617 global_proxy =
618 ReinitializeJSGlobalProxy(
619 global_proxy_function,
620 Handle<JSGlobalProxy>::cast(global_object));
621 } else {
622 global_proxy = Handle<JSGlobalProxy>::cast(
623 Factory::NewJSObject(global_proxy_function, TENURED));
624 }
625
626 // Security setup: Set the security token of the global object to
627 // its the inner global. This makes the security check between two
628 // different contexts fail by default even in case of global
629 // object reinitialization.
630 object->set_global_receiver(*global_proxy);
631 global_proxy->set_context(*global_context());
632 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000633
634 { // --- G l o b a l C o n t e x t ---
635 // use the empty function as closure (no scope info)
636 global_context()->set_closure(*empty_function);
637 global_context()->set_fcontext(*global_context());
638 global_context()->set_previous(NULL);
639
640 // set extension and global object
641 global_context()->set_extension(*object);
642 global_context()->set_global(*object);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000643 global_context()->set_global_proxy(*global_proxy);
644 // use inner global object as security token by default
645 global_context()->set_security_token(*object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000646 }
647
648 Handle<JSObject> global = Handle<JSObject>(global_context()->global());
649 SetProperty(global, object_name, Top::object_function(), DONT_ENUM);
650 }
651
652 Handle<JSObject> global = Handle<JSObject>(global_context()->global());
653
654 // Install global Function object
655 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize,
656 empty_function, Builtins::Illegal, true); // ECMA native.
657
658 { // --- A r r a y ---
659 Handle<JSFunction> array_function =
660 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize,
661 Top::initial_object_prototype(), Builtins::ArrayCode,
662 true);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000663 array_function->shared()->DontAdaptArguments();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000664
665 // This seems a bit hackish, but we need to make sure Array.length
666 // is 1.
667 array_function->shared()->set_length(1);
668 Handle<DescriptorArray> array_descriptors =
669 Factory::CopyAppendProxyDescriptor(
670 Factory::empty_descriptor_array(),
671 Factory::length_symbol(),
672 Factory::NewProxy(&Accessors::ArrayLength),
673 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE));
674
675 // Cache the fast JavaScript array map
676 global_context()->set_js_array_map(array_function->initial_map());
677 global_context()->js_array_map()->set_instance_descriptors(
678 *array_descriptors);
679 // array_function is used internally. JS code creating array object should
680 // search for the 'Array' property on the global object and use that one
681 // as the constructor. 'Array' property on a global object can be
682 // overwritten by JS code.
683 global_context()->set_array_function(*array_function);
684 }
685
686 { // --- N u m b e r ---
687 Handle<JSFunction> number_fun =
688 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize,
689 Top::initial_object_prototype(), Builtins::Illegal,
690 true);
691 global_context()->set_number_function(*number_fun);
692 }
693
694 { // --- B o o l e a n ---
695 Handle<JSFunction> boolean_fun =
696 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize,
697 Top::initial_object_prototype(), Builtins::Illegal,
698 true);
699 global_context()->set_boolean_function(*boolean_fun);
700 }
701
702 { // --- S t r i n g ---
703 Handle<JSFunction> string_fun =
704 InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize,
705 Top::initial_object_prototype(), Builtins::Illegal,
706 true);
707 global_context()->set_string_function(*string_fun);
708 // Add 'length' property to strings.
709 Handle<DescriptorArray> string_descriptors =
710 Factory::CopyAppendProxyDescriptor(
711 Factory::empty_descriptor_array(),
712 Factory::length_symbol(),
713 Factory::NewProxy(&Accessors::StringLength),
714 static_cast<PropertyAttributes>(DONT_ENUM |
715 DONT_DELETE |
716 READ_ONLY));
717
718 Handle<Map> string_map =
719 Handle<Map>(global_context()->string_function()->initial_map());
720 string_map->set_instance_descriptors(*string_descriptors);
721 }
722
723 { // --- D a t e ---
724 // Builtin functions for Date.prototype.
725 Handle<JSFunction> date_fun =
726 InstallFunction(global, "Date", JS_VALUE_TYPE, JSValue::kSize,
727 Top::initial_object_prototype(), Builtins::Illegal,
728 true);
729
730 global_context()->set_date_function(*date_fun);
731 }
732
733
734 { // -- R e g E x p
735 // Builtin functions for RegExp.prototype.
736 Handle<JSFunction> regexp_fun =
ager@chromium.org236ad962008-09-25 09:45:57 +0000737 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000738 Top::initial_object_prototype(), Builtins::Illegal,
739 true);
740
741 global_context()->set_regexp_function(*regexp_fun);
742 }
743
ager@chromium.org3a37e9b2009-04-27 09:26:21 +0000744 { // -- J S O N
745 Handle<String> name = Factory::NewStringFromAscii(CStrVector("JSON"));
746 Handle<JSFunction> cons = Factory::NewFunction(
747 name,
748 Factory::the_hole_value());
749 cons->SetInstancePrototype(global_context()->initial_object_prototype());
750 cons->SetInstanceClassName(*name);
751 Handle<JSObject> json_object = Factory::NewJSObject(cons, TENURED);
752 ASSERT(json_object->IsJSObject());
753 SetProperty(global, name, json_object, DONT_ENUM);
754 global_context()->set_json_object(*json_object);
755 }
756
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000757 { // --- arguments_boilerplate_
758 // Make sure we can recognize argument objects at runtime.
759 // This is done by introducing an anonymous function with
760 // class_name equals 'Arguments'.
761 Handle<String> symbol = Factory::LookupAsciiSymbol("Arguments");
762 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));
763 Handle<JSObject> prototype =
764 Handle<JSObject>(
765 JSObject::cast(global_context()->object_function()->prototype()));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000766
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000767 Handle<JSFunction> function =
768 Factory::NewFunctionWithPrototype(symbol,
769 JS_OBJECT_TYPE,
770 JSObject::kHeaderSize,
771 prototype,
772 code,
773 false);
774 ASSERT(!function->has_initial_map());
775 function->shared()->set_instance_class_name(*symbol);
776 function->shared()->set_expected_nof_properties(2);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000777 Handle<JSObject> result = Factory::NewJSObject(function);
778
779 global_context()->set_arguments_boilerplate(*result);
780 // Note: callee must be added as the first property and
v8.team.kasperl727e9952008-09-02 14:56:44 +0000781 // length must be added as the second property.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000782 SetProperty(result, Factory::callee_symbol(),
783 Factory::undefined_value(),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000784 DONT_ENUM);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000785 SetProperty(result, Factory::length_symbol(),
786 Factory::undefined_value(),
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000787 DONT_ENUM);
788
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000789#ifdef DEBUG
790 LookupResult lookup;
791 result->LocalLookup(Heap::callee_symbol(), &lookup);
792 ASSERT(lookup.IsValid() && (lookup.type() == FIELD));
793 ASSERT(lookup.GetFieldIndex() == Heap::arguments_callee_index);
794
795 result->LocalLookup(Heap::length_symbol(), &lookup);
796 ASSERT(lookup.IsValid() && (lookup.type() == FIELD));
797 ASSERT(lookup.GetFieldIndex() == Heap::arguments_length_index);
798
799 ASSERT(result->map()->inobject_properties() > Heap::arguments_callee_index);
800 ASSERT(result->map()->inobject_properties() > Heap::arguments_length_index);
801
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000802 // Check the state of the object.
803 ASSERT(result->HasFastProperties());
804 ASSERT(result->HasFastElements());
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000805#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000806 }
807
808 { // --- context extension
809 // Create a function for the context extension objects.
810 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));
811 Handle<JSFunction> context_extension_fun =
ager@chromium.org32912102009-01-16 10:38:43 +0000812 Factory::NewFunction(Factory::empty_symbol(),
813 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
814 JSObject::kHeaderSize,
815 code,
816 true);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000817
818 Handle<String> name = Factory::LookupAsciiSymbol("context_extension");
819 context_extension_fun->shared()->set_instance_class_name(*name);
820 global_context()->set_context_extension_function(*context_extension_fun);
821 }
822
823 // Setup the call-as-function delegate.
824 Handle<Code> code =
825 Handle<Code>(Builtins::builtin(Builtins::HandleApiCallAsFunction));
826 Handle<JSFunction> delegate =
827 Factory::NewFunction(Factory::empty_symbol(), JS_OBJECT_TYPE,
828 JSObject::kHeaderSize, code, true);
829 global_context()->set_call_as_function_delegate(*delegate);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +0000830 delegate->shared()->DontAdaptArguments();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000831
832 global_context()->set_special_function_table(Heap::empty_fixed_array());
833
834 // Initialize the out of memory slot.
835 global_context()->set_out_of_memory(Heap::false_value());
836}
837
838
839bool Genesis::CompileBuiltin(int index) {
840 Vector<const char> name = Natives::GetScriptName(index);
841 Handle<String> source_code = Bootstrapper::NativesSourceLookup(index);
842 return CompileNative(name, source_code);
843}
844
845
846bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) {
847 HandleScope scope;
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000848#ifdef ENABLE_DEBUGGER_SUPPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000849 Debugger::set_compiling_natives(true);
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000850#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000851 bool result =
852 CompileScriptCached(name, source, &natives_cache, NULL, true);
853 ASSERT(Top::has_pending_exception() != result);
854 if (!result) Top::clear_pending_exception();
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000855#ifdef ENABLE_DEBUGGER_SUPPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000856 Debugger::set_compiling_natives(false);
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000857#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000858 return result;
859}
860
861
862bool Genesis::CompileScriptCached(Vector<const char> name,
863 Handle<String> source,
864 SourceCodeCache* cache,
865 v8::Extension* extension,
866 bool use_runtime_context) {
867 HandleScope scope;
868 Handle<JSFunction> boilerplate;
869
870 // If we can't find the function in the cache, we compile a new
871 // function and insert it into the cache.
872 if (!cache->Lookup(name, &boilerplate)) {
ager@chromium.org5ec48922009-05-05 07:25:34 +0000873 ASSERT(source->IsAsciiRepresentation());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000874 Handle<String> script_name = Factory::NewStringFromUtf8(name);
875 boilerplate =
876 Compiler::Compile(source, script_name, 0, 0, extension, NULL);
877 if (boilerplate.is_null()) return false;
878 cache->Add(name, boilerplate);
879 }
880
881 // Setup the function context. Conceptually, we should clone the
882 // function before overwriting the context but since we're in a
883 // single-threaded environment it is not strictly necessary.
884 ASSERT(Top::context()->IsGlobalContext());
885 Handle<Context> context =
886 Handle<Context>(use_runtime_context
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000887 ? Top::context()->runtime_context()
888 : Top::context());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000889 Handle<JSFunction> fun =
890 Factory::NewFunctionFromBoilerplate(boilerplate, context);
891
892 // Call function using the either the runtime object or the global
893 // object as the receiver. Provide no parameters.
894 Handle<Object> receiver =
895 Handle<Object>(use_runtime_context
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000896 ? Top::context()->builtins()
897 : Top::context()->global());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000898 bool has_pending_exception;
899 Handle<Object> result =
900 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception);
901 if (has_pending_exception) return false;
902 return PendingFixups::Process(
903 Handle<JSBuiltinsObject>(Top::context()->builtins()));
904}
905
906
907#define INSTALL_NATIVE(Type, name, var) \
908 Handle<String> var##_name = Factory::LookupAsciiSymbol(name); \
909 global_context()->set_##var(Type::cast(global_context()-> \
910 builtins()-> \
911 GetProperty(*var##_name)));
912
913void Genesis::InstallNativeFunctions() {
914 HandleScope scope;
915 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun);
916 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun);
917 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun);
918 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun);
919 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun);
920 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun);
921 INSTALL_NATIVE(JSFunction, "ToUint32", to_uint32_fun);
922 INSTALL_NATIVE(JSFunction, "ToInt32", to_int32_fun);
923 INSTALL_NATIVE(JSFunction, "ToBoolean", to_boolean_fun);
924 INSTALL_NATIVE(JSFunction, "Instantiate", instantiate_fun);
925 INSTALL_NATIVE(JSFunction, "ConfigureTemplateInstance",
926 configure_instance_fun);
927 INSTALL_NATIVE(JSFunction, "MakeMessage", make_message_fun);
928 INSTALL_NATIVE(JSFunction, "GetStackTraceLine", get_stack_trace_line_fun);
929 INSTALL_NATIVE(JSObject, "functionCache", function_cache);
930}
931
932#undef INSTALL_NATIVE
933
934
935bool Genesis::InstallNatives() {
936 HandleScope scope;
937
938 // Create a function for the builtins object. Allocate space for the
939 // JavaScript builtins, a reference to the builtins object
940 // (itself) and a reference to the global_context directly in the object.
941 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));
942 Handle<JSFunction> builtins_fun =
943 Factory::NewFunction(Factory::empty_symbol(), JS_BUILTINS_OBJECT_TYPE,
944 JSBuiltinsObject::kSize, code, true);
945
946 Handle<String> name = Factory::LookupAsciiSymbol("builtins");
947 builtins_fun->shared()->set_instance_class_name(*name);
948 SetExpectedNofProperties(builtins_fun, 100);
949
950 // Allocate the builtins object.
951 Handle<JSBuiltinsObject> builtins =
952 Handle<JSBuiltinsObject>::cast(Factory::NewJSObject(builtins_fun,
953 TENURED));
954 builtins->set_builtins(*builtins);
955 builtins->set_global_context(*global_context());
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000956 builtins->set_global_receiver(*builtins);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000957
958 // Setup the 'global' properties of the builtins object. The
959 // 'global' property that refers to the global object is the only
960 // way to get from code running in the builtins context to the
961 // global object.
962 static const PropertyAttributes attributes =
963 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
964 SetProperty(builtins, Factory::LookupAsciiSymbol("global"),
965 Handle<Object>(global_context()->global()), attributes);
966
967 // Setup the reference from the global object to the builtins object.
968 JSGlobalObject::cast(global_context()->global())->set_builtins(*builtins);
969
970 // Create a bridge function that has context in the global context.
971 Handle<JSFunction> bridge =
972 Factory::NewFunction(Factory::empty_symbol(), Factory::undefined_value());
973 ASSERT(bridge->context() == *Top::global_context());
974
975 // Allocate the builtins context.
976 Handle<Context> context =
977 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge);
978 context->set_global(*builtins); // override builtins global object
979
980 global_context()->set_runtime_context(*context);
981
982 { // -- S c r i p t
983 // Builtin functions for Script.
984 Handle<JSFunction> script_fun =
985 InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize,
986 Top::initial_object_prototype(), Builtins::Illegal,
987 false);
988 Handle<JSObject> prototype =
989 Factory::NewJSObject(Top::object_function(), TENURED);
990 SetPrototype(script_fun, prototype);
991 global_context()->set_script_function(*script_fun);
992
993 // Add 'source' and 'data' property to scripts.
994 PropertyAttributes common_attributes =
995 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY);
996 Handle<Proxy> proxy_source = Factory::NewProxy(&Accessors::ScriptSource);
997 Handle<DescriptorArray> script_descriptors =
998 Factory::CopyAppendProxyDescriptor(
999 Factory::empty_descriptor_array(),
1000 Factory::LookupAsciiSymbol("source"),
1001 proxy_source,
1002 common_attributes);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001003 Handle<Proxy> proxy_name = Factory::NewProxy(&Accessors::ScriptName);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001004 script_descriptors =
1005 Factory::CopyAppendProxyDescriptor(
1006 script_descriptors,
1007 Factory::LookupAsciiSymbol("name"),
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001008 proxy_name,
1009 common_attributes);
1010 Handle<Proxy> proxy_id = Factory::NewProxy(&Accessors::ScriptId);
1011 script_descriptors =
1012 Factory::CopyAppendProxyDescriptor(
1013 script_descriptors,
1014 Factory::LookupAsciiSymbol("id"),
1015 proxy_id,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001016 common_attributes);
1017 Handle<Proxy> proxy_line_offset =
1018 Factory::NewProxy(&Accessors::ScriptLineOffset);
1019 script_descriptors =
1020 Factory::CopyAppendProxyDescriptor(
1021 script_descriptors,
1022 Factory::LookupAsciiSymbol("line_offset"),
1023 proxy_line_offset,
1024 common_attributes);
1025 Handle<Proxy> proxy_column_offset =
1026 Factory::NewProxy(&Accessors::ScriptColumnOffset);
1027 script_descriptors =
1028 Factory::CopyAppendProxyDescriptor(
1029 script_descriptors,
1030 Factory::LookupAsciiSymbol("column_offset"),
1031 proxy_column_offset,
1032 common_attributes);
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001033 Handle<Proxy> proxy_data = Factory::NewProxy(&Accessors::ScriptData);
1034 script_descriptors =
1035 Factory::CopyAppendProxyDescriptor(
1036 script_descriptors,
1037 Factory::LookupAsciiSymbol("data"),
1038 proxy_data,
1039 common_attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001040 Handle<Proxy> proxy_type = Factory::NewProxy(&Accessors::ScriptType);
1041 script_descriptors =
1042 Factory::CopyAppendProxyDescriptor(
1043 script_descriptors,
1044 Factory::LookupAsciiSymbol("type"),
1045 proxy_type,
1046 common_attributes);
iposva@chromium.org245aa852009-02-10 00:49:54 +00001047 Handle<Proxy> proxy_line_ends =
1048 Factory::NewProxy(&Accessors::ScriptLineEnds);
1049 script_descriptors =
1050 Factory::CopyAppendProxyDescriptor(
1051 script_descriptors,
1052 Factory::LookupAsciiSymbol("line_ends"),
1053 proxy_line_ends,
1054 common_attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001055
1056 Handle<Map> script_map = Handle<Map>(script_fun->initial_map());
1057 script_map->set_instance_descriptors(*script_descriptors);
1058
1059 // Allocate the empty script.
1060 Handle<Script> script = Factory::NewScript(Factory::empty_string());
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001061 script->set_type(Smi::FromInt(SCRIPT_TYPE_NATIVE));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001062 global_context()->set_empty_script(*script);
1063 }
1064
1065 if (FLAG_natives_file == NULL) {
1066 // Without natives file, install default natives.
1067 for (int i = Natives::GetDelayCount();
1068 i < Natives::GetBuiltinsCount();
1069 i++) {
1070 if (!CompileBuiltin(i)) return false;
1071 }
1072
1073 // Setup natives with lazy loading.
1074 SetupLazy(Handle<JSFunction>(global_context()->date_function()),
1075 Natives::GetIndex("date"),
1076 Top::global_context(),
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001077 Handle<Context>(Top::context()->runtime_context()));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001078 SetupLazy(Handle<JSFunction>(global_context()->regexp_function()),
1079 Natives::GetIndex("regexp"),
1080 Top::global_context(),
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001081 Handle<Context>(Top::context()->runtime_context()));
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00001082 SetupLazy(Handle<JSObject>(global_context()->json_object()),
1083 Natives::GetIndex("json"),
1084 Top::global_context(),
1085 Handle<Context>(Top::context()->runtime_context()));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001086
1087 } else if (strlen(FLAG_natives_file) != 0) {
1088 // Otherwise install natives from natives file if file exists and
1089 // compiles.
1090 bool exists;
1091 Vector<const char> source = ReadFile(FLAG_natives_file, &exists);
1092 Handle<String> source_string = Factory::NewStringFromAscii(source);
1093 if (source.is_empty()) return false;
1094 bool result = CompileNative(CStrVector(FLAG_natives_file), source_string);
1095 if (!result) return false;
1096
1097 } else {
1098 // Empty natives file name - do not install any natives.
1099 PrintF("Warning: Running without installed natives!\n");
1100 return true;
1101 }
1102
1103 InstallNativeFunctions();
1104
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001105 // Install Function.prototype.call and apply.
1106 { Handle<String> key = Factory::function_class_symbol();
1107 Handle<JSFunction> function =
1108 Handle<JSFunction>::cast(GetProperty(Top::global(), key));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001109 Handle<JSObject> proto =
1110 Handle<JSObject>(JSObject::cast(function->instance_prototype()));
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001111
1112 // Install the call and the apply functions.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001113 Handle<JSFunction> call =
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001114 InstallFunction(proto, "call", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1115 Factory::NewJSObject(Top::object_function(), TENURED),
1116 Builtins::FunctionCall,
1117 false);
1118 Handle<JSFunction> apply =
1119 InstallFunction(proto, "apply", JS_OBJECT_TYPE, JSObject::kHeaderSize,
1120 Factory::NewJSObject(Top::object_function(), TENURED),
1121 Builtins::FunctionApply,
1122 false);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001123
1124 // Make sure that Function.prototype.call appears to be compiled.
1125 // The code will never be called, but inline caching for call will
1126 // only work if it appears to be compiled.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001127 call->shared()->DontAdaptArguments();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001128 ASSERT(call->is_compiled());
1129
ager@chromium.org32912102009-01-16 10:38:43 +00001130 // Set the expected parameters for apply to 2; required by builtin.
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001131 apply->shared()->set_formal_parameter_count(2);
1132
1133 // Set the lengths for the functions to satisfy ECMA-262.
1134 call->shared()->set_length(1);
1135 apply->shared()->set_length(2);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001136 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001137
1138 // Make sure that the builtins object has fast properties.
1139 // If the ASSERT below fails, please increase the expected number of
1140 // properties for the builtins object.
1141 ASSERT(builtins->HasFastProperties());
1142#ifdef DEBUG
1143 builtins->Verify();
1144#endif
1145 return true;
1146}
1147
1148
mads.s.agercbaa0602008-08-14 13:41:48 +00001149bool Genesis::InstallSpecialObjects() {
1150 HandleScope scope;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001151 Handle<JSGlobalObject> js_global(
mads.s.agercbaa0602008-08-14 13:41:48 +00001152 JSGlobalObject::cast(global_context()->global()));
1153 // Expose the natives in global if a name for it is specified.
1154 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
1155 Handle<String> natives_string =
1156 Factory::LookupAsciiSymbol(FLAG_expose_natives_as);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001157 SetProperty(js_global, natives_string,
1158 Handle<JSObject>(js_global->builtins()), DONT_ENUM);
mads.s.agercbaa0602008-08-14 13:41:48 +00001159 }
1160
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001161#ifdef ENABLE_DEBUGGER_SUPPORT
mads.s.agercbaa0602008-08-14 13:41:48 +00001162 // Expose the debug global object in global if a name for it is specified.
1163 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) {
1164 // If loading fails we just bail out without installing the
1165 // debugger but without tanking the whole context.
1166 if (!Debug::Load())
1167 return true;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001168 // Set the security token for the debugger context to the same as
1169 // the shell global context to allow calling between these (otherwise
1170 // exposing debug global object doesn't make much sense).
1171 Debug::debug_context()->set_security_token(
1172 global_context()->security_token());
1173
mads.s.agercbaa0602008-08-14 13:41:48 +00001174 Handle<String> debug_string =
1175 Factory::LookupAsciiSymbol(FLAG_expose_debug_as);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001176 SetProperty(js_global, debug_string,
1177 Handle<Object>(Debug::debug_context()->global_proxy()), DONT_ENUM);
mads.s.agercbaa0602008-08-14 13:41:48 +00001178 }
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001179#endif
mads.s.agercbaa0602008-08-14 13:41:48 +00001180
1181 return true;
1182}
1183
1184
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001185bool Genesis::InstallExtensions(v8::ExtensionConfiguration* extensions) {
1186 // Clear coloring of extension list
1187 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension();
1188 while (current != NULL) {
1189 current->set_state(v8::UNVISITED);
1190 current = current->next();
1191 }
1192 // Install auto extensions
1193 current = v8::RegisteredExtension::first_extension();
1194 while (current != NULL) {
1195 if (current->extension()->auto_enable())
1196 InstallExtension(current);
1197 current = current->next();
1198 }
1199
1200 if (FLAG_expose_gc) InstallExtension("v8/gc");
1201
1202 if (extensions == NULL) return true;
1203 // Install required extensions
1204 int count = v8::ImplementationUtilities::GetNameCount(extensions);
1205 const char** names = v8::ImplementationUtilities::GetNames(extensions);
1206 for (int i = 0; i < count; i++) {
1207 if (!InstallExtension(names[i]))
1208 return false;
1209 }
1210
1211 return true;
1212}
1213
1214
1215// Installs a named extension. This methods is unoptimized and does
1216// not scale well if we want to support a large number of extensions.
1217bool Genesis::InstallExtension(const char* name) {
1218 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension();
1219 // Loop until we find the relevant extension
1220 while (current != NULL) {
1221 if (strcmp(name, current->extension()->name()) == 0) break;
1222 current = current->next();
1223 }
1224 // Didn't find the extension; fail.
1225 if (current == NULL) {
1226 v8::Utils::ReportApiFailure(
1227 "v8::Context::New()", "Cannot find required extension");
1228 return false;
1229 }
1230 return InstallExtension(current);
1231}
1232
1233
1234bool Genesis::InstallExtension(v8::RegisteredExtension* current) {
1235 HandleScope scope;
1236
1237 if (current->state() == v8::INSTALLED) return true;
1238 // The current node has already been visited so there must be a
1239 // cycle in the dependency graph; fail.
1240 if (current->state() == v8::VISITED) {
1241 v8::Utils::ReportApiFailure(
1242 "v8::Context::New()", "Circular extension dependency");
1243 return false;
1244 }
1245 ASSERT(current->state() == v8::UNVISITED);
1246 current->set_state(v8::VISITED);
1247 v8::Extension* extension = current->extension();
1248 // Install the extension's dependencies
1249 for (int i = 0; i < extension->dependency_count(); i++) {
1250 if (!InstallExtension(extension->dependencies()[i])) return false;
1251 }
1252 Vector<const char> source = CStrVector(extension->source());
1253 Handle<String> source_code = Factory::NewStringFromAscii(source);
1254 bool result = CompileScriptCached(CStrVector(extension->name()),
1255 source_code,
1256 &extensions_cache, extension,
1257 false);
1258 ASSERT(Top::has_pending_exception() != result);
1259 if (!result) {
1260 Top::clear_pending_exception();
1261 v8::Utils::ReportApiFailure(
1262 "v8::Context::New()", "Error installing extension");
1263 }
1264 current->set_state(v8::INSTALLED);
1265 return result;
1266}
1267
1268
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001269bool Genesis::ConfigureGlobalObjects(
1270 v8::Handle<v8::ObjectTemplate> global_proxy_template) {
1271 Handle<JSObject> global_proxy(
1272 JSObject::cast(global_context()->global_proxy()));
1273 Handle<JSObject> js_global(JSObject::cast(global_context()->global()));
1274
1275 if (!global_proxy_template.IsEmpty()) {
1276 // Configure the global proxy object.
1277 Handle<ObjectTemplateInfo> proxy_data =
1278 v8::Utils::OpenHandle(*global_proxy_template);
1279 if (!ConfigureApiObject(global_proxy, proxy_data)) return false;
1280
1281 // Configure the inner global object.
1282 Handle<FunctionTemplateInfo> proxy_constructor(
1283 FunctionTemplateInfo::cast(proxy_data->constructor()));
1284 if (!proxy_constructor->prototype_template()->IsUndefined()) {
1285 Handle<ObjectTemplateInfo> inner_data(
1286 ObjectTemplateInfo::cast(proxy_constructor->prototype_template()));
1287 if (!ConfigureApiObject(js_global, inner_data)) return false;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001288 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001289 }
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001290
1291 SetObjectPrototype(global_proxy, js_global);
1292 return true;
1293}
1294
1295
1296bool Genesis::ConfigureApiObject(Handle<JSObject> object,
1297 Handle<ObjectTemplateInfo> object_template) {
1298 ASSERT(!object_template.is_null());
1299 ASSERT(object->IsInstanceOf(
1300 FunctionTemplateInfo::cast(object_template->constructor())));
1301
1302 bool pending_exception = false;
1303 Handle<JSObject> obj =
1304 Execution::InstantiateObject(object_template, &pending_exception);
1305 if (pending_exception) {
1306 ASSERT(Top::has_pending_exception());
1307 Top::clear_pending_exception();
1308 return false;
1309 }
1310 TransferObject(obj, object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001311 return true;
1312}
1313
1314
1315void Genesis::TransferNamedProperties(Handle<JSObject> from,
1316 Handle<JSObject> to) {
1317 if (from->HasFastProperties()) {
1318 Handle<DescriptorArray> descs =
1319 Handle<DescriptorArray>(from->map()->instance_descriptors());
1320 int offset = 0;
1321 while (true) {
1322 // Iterating through the descriptors is not gc safe so we have to
1323 // store the value in a handle and create a new stream for each entry.
1324 DescriptorReader stream(*descs, offset);
1325 if (stream.eos()) break;
1326 // We have to read out the next offset before we do anything that may
1327 // cause a gc, since the DescriptorReader is not gc safe.
1328 offset = stream.next_position();
1329 PropertyDetails details = stream.GetDetails();
1330 switch (details.type()) {
1331 case FIELD: {
1332 HandleScope inner;
1333 Handle<String> key = Handle<String>(stream.GetKey());
1334 int index = stream.GetFieldIndex();
ager@chromium.org7c537e22008-10-16 08:43:32 +00001335 Handle<Object> value = Handle<Object>(from->FastPropertyAt(index));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001336 SetProperty(to, key, value, details.attributes());
1337 break;
1338 }
1339 case CONSTANT_FUNCTION: {
1340 HandleScope inner;
1341 Handle<String> key = Handle<String>(stream.GetKey());
1342 Handle<JSFunction> fun =
1343 Handle<JSFunction>(stream.GetConstantFunction());
1344 SetProperty(to, key, fun, details.attributes());
1345 break;
1346 }
1347 case CALLBACKS: {
1348 LookupResult result;
1349 to->LocalLookup(stream.GetKey(), &result);
1350 // If the property is already there we skip it
1351 if (result.IsValid()) continue;
1352 HandleScope inner;
1353 Handle<DescriptorArray> inst_descs =
1354 Handle<DescriptorArray>(to->map()->instance_descriptors());
1355 Handle<String> key = Handle<String>(stream.GetKey());
1356 Handle<Object> entry = Handle<Object>(stream.GetCallbacksObject());
1357 inst_descs = Factory::CopyAppendProxyDescriptor(inst_descs,
1358 key,
1359 entry,
1360 details.attributes());
1361 to->map()->set_instance_descriptors(*inst_descs);
1362 break;
1363 }
1364 case MAP_TRANSITION:
1365 case CONSTANT_TRANSITION:
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001366 case NULL_DESCRIPTOR:
1367 // Ignore non-properties.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001368 break;
1369 case NORMAL:
1370 // Do not occur since the from object has fast properties.
1371 case INTERCEPTOR:
1372 // No element in instance descriptors have interceptor type.
1373 UNREACHABLE();
1374 break;
1375 }
1376 }
1377 } else {
1378 Handle<Dictionary> properties =
1379 Handle<Dictionary>(from->property_dictionary());
1380 int capacity = properties->Capacity();
1381 for (int i = 0; i < capacity; i++) {
1382 Object* raw_key(properties->KeyAt(i));
1383 if (properties->IsKey(raw_key)) {
1384 ASSERT(raw_key->IsString());
1385 // If the property is already there we skip it.
1386 LookupResult result;
1387 to->LocalLookup(String::cast(raw_key), &result);
1388 if (result.IsValid()) continue;
1389 // Set the property.
1390 Handle<String> key = Handle<String>(String::cast(raw_key));
1391 Handle<Object> value = Handle<Object>(properties->ValueAt(i));
1392 PropertyDetails details = properties->DetailsAt(i);
1393 SetProperty(to, key, value, details.attributes());
1394 }
1395 }
1396 }
1397}
1398
1399
1400void Genesis::TransferIndexedProperties(Handle<JSObject> from,
1401 Handle<JSObject> to) {
1402 // Cloning the elements array is sufficient.
1403 Handle<FixedArray> from_elements =
1404 Handle<FixedArray>(FixedArray::cast(from->elements()));
1405 Handle<FixedArray> to_elements = Factory::CopyFixedArray(from_elements);
1406 to->set_elements(*to_elements);
1407}
1408
1409
1410void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) {
1411 HandleScope outer;
1412
1413 ASSERT(!from->IsJSArray());
1414 ASSERT(!to->IsJSArray());
1415
1416 TransferNamedProperties(from, to);
1417 TransferIndexedProperties(from, to);
1418
1419 // Transfer the prototype (new map is needed).
1420 Handle<Map> old_to_map = Handle<Map>(to->map());
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001421 Handle<Map> new_to_map = Factory::CopyMapDropTransitions(old_to_map);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001422 new_to_map->set_prototype(from->map()->prototype());
1423 to->set_map(*new_to_map);
1424}
1425
1426
1427void Genesis::MakeFunctionInstancePrototypeWritable() {
1428 // Make a new function map so all future functions
kasper.lund7276f142008-07-30 08:49:36 +00001429 // will have settable and enumerable prototype properties.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001430 HandleScope scope;
1431
1432 Handle<DescriptorArray> function_map_descriptors =
kasper.lund7276f142008-07-30 08:49:36 +00001433 ComputeFunctionInstanceDescriptor(false, true);
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00001434 Handle<Map> fm = Factory::CopyMapDropDescriptors(Top::function_map());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001435 fm->set_instance_descriptors(*function_map_descriptors);
1436 Top::context()->global_context()->set_function_map(*fm);
1437}
1438
1439
1440void Genesis::AddSpecialFunction(Handle<JSObject> prototype,
1441 const char* name,
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001442 Handle<Code> code) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001443 Handle<String> key = Factory::LookupAsciiSymbol(name);
1444 Handle<Object> value = Handle<Object>(prototype->GetProperty(*key));
1445 if (value->IsJSFunction()) {
1446 Handle<JSFunction> optimized = Factory::NewFunction(key,
1447 JS_OBJECT_TYPE,
1448 JSObject::kHeaderSize,
1449 code,
1450 false);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001451 optimized->shared()->DontAdaptArguments();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001452 int len = global_context()->special_function_table()->length();
1453 Handle<FixedArray> new_array = Factory::NewFixedArray(len + 3);
1454 for (int index = 0; index < len; index++) {
1455 new_array->set(index,
1456 global_context()->special_function_table()->get(index));
1457 }
1458 new_array->set(len+0, *prototype);
1459 new_array->set(len+1, *value);
1460 new_array->set(len+2, *optimized);
1461 global_context()->set_special_function_table(*new_array);
1462 }
1463}
1464
1465
1466void Genesis::BuildSpecialFunctionTable() {
1467 HandleScope scope;
1468 Handle<JSObject> global = Handle<JSObject>(global_context()->global());
1469 // Add special versions for Array.prototype.pop and push.
1470 Handle<JSFunction> function =
1471 Handle<JSFunction>(
1472 JSFunction::cast(global->GetProperty(Heap::Array_symbol())));
1473 Handle<JSObject> prototype =
1474 Handle<JSObject>(JSObject::cast(function->prototype()));
1475 AddSpecialFunction(prototype, "pop",
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001476 Handle<Code>(Builtins::builtin(Builtins::ArrayPop)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001477 AddSpecialFunction(prototype, "push",
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00001478 Handle<Code>(Builtins::builtin(Builtins::ArrayPush)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001479}
1480
1481
1482Genesis::Genesis(Handle<Object> global_object,
1483 v8::Handle<v8::ObjectTemplate> global_template,
1484 v8::ExtensionConfiguration* extensions) {
1485 // Link this genesis object into the stacked genesis chain. This
ager@chromium.org32912102009-01-16 10:38:43 +00001486 // must be done before any early exits because the destructor
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001487 // will always do unlinking.
1488 previous_ = current_;
1489 current_ = this;
1490 result_ = NULL;
1491
1492 // If V8 hasn't been and cannot be initialized, just return.
1493 if (!V8::HasBeenSetup() && !V8::Initialize(NULL)) return;
1494
1495 // Before creating the roots we must save the context and restore it
1496 // on all function exits.
1497 HandleScope scope;
1498 SaveContext context;
1499
1500 CreateRoots(global_template, global_object);
1501 if (!InstallNatives()) return;
1502
1503 MakeFunctionInstancePrototypeWritable();
1504 BuildSpecialFunctionTable();
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001505
1506 if (!ConfigureGlobalObjects(global_template)) return;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001507
1508 if (!InstallExtensions(extensions)) return;
1509
mads.s.agercbaa0602008-08-14 13:41:48 +00001510 if (!InstallSpecialObjects()) return;
1511
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001512 result_ = global_context_;
1513}
1514
ager@chromium.orgddb913d2009-01-27 10:01:48 +00001515
1516// Support for thread preemption.
1517
1518// Reserve space for statics needing saving and restoring.
1519int Bootstrapper::ArchiveSpacePerThread() {
1520 return Genesis::ArchiveSpacePerThread();
1521}
1522
1523
1524// Archive statics that are thread local.
1525char* Bootstrapper::ArchiveState(char* to) {
1526 return Genesis::ArchiveState(to);
1527}
1528
1529
1530// Restore statics that are thread local.
1531char* Bootstrapper::RestoreState(char* from) {
1532 return Genesis::RestoreState(from);
1533}
1534
1535
1536// Reserve space for statics needing saving and restoring.
1537int Genesis::ArchiveSpacePerThread() {
1538 return sizeof(current_);
1539}
1540
1541
1542// Archive statics that are thread local.
1543char* Genesis::ArchiveState(char* to) {
1544 *reinterpret_cast<Genesis**>(to) = current_;
1545 current_ = NULL;
1546 return to + sizeof(current_);
1547}
1548
1549
1550// Restore statics that are thread local.
1551char* Genesis::RestoreState(char* from) {
1552 current_ = *reinterpret_cast<Genesis**>(from);
1553 return from + sizeof(current_);
1554}
1555
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001556} } // namespace v8::internal