45 static C* FindInstanceOf(
Object* obj) {
46 for (
Object* cur = obj; !cur->IsNull(); cur = cur->GetPrototype()) {
47 if (Is<C>(cur))
return C::cast(cur);
54 MaybeObject* Accessors::IllegalSetter(JSObject*,
Object*,
void*) {
60 Object* Accessors::IllegalGetAccessor(
Object*
object,
void*) {
66 MaybeObject* Accessors::ReadOnlySetAccessor(JSObject*,
Object* value,
void*) {
78 MaybeObject* Accessors::ArrayGetLength(
Object*
object,
void*) {
80 JSArray* holder = FindInstanceOf<JSArray>(object);
87 if (value->IsNumber() || !value->IsJSValue())
return value;
89 ASSERT(Isolate::Current()->context()->native_context()->number_function()->
91 Map* number_map = Isolate::Current()->context()->native_context()->
92 number_function()->initial_map();
93 if (wrapper->map() == number_map)
return wrapper->value();
98 MaybeObject* Accessors::ArraySetLength(JSObject*
object,
Object* value,
void*) {
99 Isolate* isolate =
object->GetIsolate();
104 if (!object->IsJSArray()) {
105 return object->SetLocalPropertyIgnoreAttributes(
106 isolate->heap()->length_symbol(), value,
NONE);
109 value = FlattenNumber(value);
112 HandleScope scope(isolate);
115 Handle<JSObject> object_handle(
object, isolate);
116 Handle<Object> value_handle(value, isolate);
124 if (uint32_v->Number() == number_v->Number()) {
127 return isolate->Throw(
128 *isolate->factory()->NewRangeError(
"invalid_array_length",
129 HandleVector<Object>(
NULL, 0)));
133 const AccessorDescriptor Accessors::ArrayLength = {
145 MaybeObject* Accessors::StringGetLength(
Object*
object,
void*) {
147 if (object->IsJSValue()) value =
JSValue::cast(
object)->value();
155 const AccessorDescriptor Accessors::StringLength = {
167 MaybeObject* Accessors::ScriptGetSource(
Object*
object,
void*) {
173 const AccessorDescriptor Accessors::ScriptSource = {
185 MaybeObject* Accessors::ScriptGetName(
Object*
object,
void*) {
191 const AccessorDescriptor Accessors::ScriptName = {
203 MaybeObject* Accessors::ScriptGetId(
Object*
object,
void*) {
209 const AccessorDescriptor Accessors::ScriptId = {
221 MaybeObject* Accessors::ScriptGetLineOffset(
Object*
object,
void*) {
227 const AccessorDescriptor Accessors::ScriptLineOffset = {
239 MaybeObject* Accessors::ScriptGetColumnOffset(
Object*
object,
void*) {
245 const AccessorDescriptor Accessors::ScriptColumnOffset = {
246 ScriptGetColumnOffset,
257 MaybeObject* Accessors::ScriptGetData(
Object*
object,
void*) {
263 const AccessorDescriptor Accessors::ScriptData = {
275 MaybeObject* Accessors::ScriptGetType(
Object*
object,
void*) {
281 const AccessorDescriptor Accessors::ScriptType = {
293 MaybeObject* Accessors::ScriptGetCompilationType(
Object*
object,
void*) {
299 const AccessorDescriptor Accessors::ScriptCompilationType = {
300 ScriptGetCompilationType,
311 MaybeObject* Accessors::ScriptGetLineEnds(
Object*
object,
void*) {
313 Isolate* isolate = wrapper->GetIsolate();
314 HandleScope scope(isolate);
315 Handle<Script> script(
Script::cast(wrapper->value()), isolate);
317 ASSERT(script->line_ends()->IsFixedArray());
320 ASSERT(*line_ends == isolate->heap()->empty_fixed_array() ||
321 line_ends->map() == isolate->heap()->fixed_cow_array_map());
322 Handle<JSArray> js_array =
323 isolate->factory()->NewJSArrayWithElements(line_ends);
328 const AccessorDescriptor Accessors::ScriptLineEnds = {
340 MaybeObject* Accessors::ScriptGetContextData(
Object*
object,
void*) {
346 const AccessorDescriptor Accessors::ScriptContextData = {
347 ScriptGetContextData,
358 MaybeObject* Accessors::ScriptGetEvalFromScript(
Object*
object,
void*) {
360 if (!
Script::cast(script)->eval_from_shared()->IsUndefined()) {
361 Handle<SharedFunctionInfo> eval_from_shared(
364 if (eval_from_shared->script()->IsScript()) {
365 Handle<Script> eval_from_script(
Script::cast(eval_from_shared->script()));
369 return HEAP->undefined_value();
373 const AccessorDescriptor Accessors::ScriptEvalFromScript = {
374 ScriptGetEvalFromScript,
385 MaybeObject* Accessors::ScriptGetEvalFromScriptPosition(
Object*
object,
void*) {
390 int compilation_type =
Smi::cast(script->compilation_type())->value();
392 return HEAP->undefined_value();
398 script->eval_from_shared())->
code());
400 script->eval_from_instructions_offset()->value()));
404 const AccessorDescriptor Accessors::ScriptEvalFromScriptPosition = {
405 ScriptGetEvalFromScriptPosition,
416 MaybeObject* Accessors::ScriptGetEvalFromFunctionName(
Object*
object,
void*) {
423 if (!shared->name()->IsUndefined()) {
424 return shared->name();
426 return shared->inferred_name();
431 const AccessorDescriptor Accessors::ScriptEvalFromFunctionName = {
432 ScriptGetEvalFromFunctionName,
444 Heap* heap = Isolate::Current()->heap();
445 JSFunction*
function = FindInstanceOf<JSFunction>(object);
446 if (
function ==
NULL)
return heap->undefined_value();
447 while (!function->should_have_prototype()) {
448 function = FindInstanceOf<JSFunction>(
function->GetPrototype());
453 if (!function->has_prototype()) {
456 if (!maybe_prototype->ToObject(&prototype))
return maybe_prototype;
459 { MaybeObject* maybe_result =
function->SetPrototype(prototype);
460 if (!maybe_result->ToObject(&result))
return maybe_result;
463 return function->prototype();
470 Heap* heap =
object->GetHeap();
471 JSFunction*
function = FindInstanceOf<JSFunction>(object);
472 if (
function ==
NULL)
return heap->undefined_value();
473 if (!function->should_have_prototype()) {
475 return object->SetLocalPropertyIgnoreAttributes(heap->prototype_symbol(),
481 { MaybeObject* maybe_prototype =
function->SetPrototype(value);
482 if (!maybe_prototype->ToObject(&prototype))
return maybe_prototype;
484 ASSERT(function->prototype() == value);
490 FunctionGetPrototype,
491 FunctionSetPrototype,
501 MaybeObject* Accessors::FunctionGetLength(
Object*
object,
void*) {
502 JSFunction*
function = FindInstanceOf<JSFunction>(object);
505 if (function->shared()->is_compiled()) {
511 Handle<JSFunction> handle(
function);
519 const AccessorDescriptor Accessors::FunctionLength = {
531 MaybeObject* Accessors::FunctionGetName(
Object*
object,
void*) {
532 JSFunction* holder = FindInstanceOf<JSFunction>(object);
533 return holder ==
NULL ?
HEAP->undefined_value() : holder->shared()->name();
537 const AccessorDescriptor Accessors::FunctionName = {
549 static MaybeObject* ConstructArgumentsObjectForInlinedFunction(
550 JavaScriptFrame* frame,
551 Handle<JSFunction> inlined_function,
552 int inlined_frame_index) {
553 Factory* factory = Isolate::Current()->factory();
554 Vector<SlotRef> args_slots =
555 SlotRef::ComputeSlotMappingForArguments(
558 inlined_function->shared()->formal_parameter_count());
559 int args_count = args_slots.length();
560 Handle<JSObject> arguments =
561 factory->NewArgumentsObject(inlined_function, args_count);
562 Handle<FixedArray> array = factory->NewFixedArray(args_count);
563 for (
int i = 0; i < args_count; ++i) {
564 Handle<Object> value = args_slots[i].GetValue();
565 array->set(i, *value);
567 arguments->set_elements(*array);
568 args_slots.Dispose();
576 Isolate* isolate = Isolate::Current();
578 JSFunction* holder = FindInstanceOf<JSFunction>(object);
579 if (holder ==
NULL)
return isolate->
heap()->undefined_value();
582 if (function->shared()->native())
return isolate->
heap()->null_value();
588 for (
int i = functions.length() - 1; i >= 0; i--) {
590 if (functions[i] != *
function)
continue;
597 return ConstructArgumentsObjectForInlinedFunction(frame,
function, i);
600 if (!frame->is_optimized()) {
603 int index = scope_info->StackSlotIndex(
604 isolate->
heap()->arguments_symbol());
607 if (!arguments->IsArgumentsMarker())
return *arguments;
614 it.AdvanceToArgumentsFrame();
625 ASSERT(array->length() == length);
626 for (
int i = 0; i < length; i++) array->set(i, frame->
GetParameter(i));
627 arguments->set_elements(*array);
636 return isolate->
heap()->null_value();
641 FunctionGetArguments,
652 static MaybeObject* CheckNonStrictCallerOrThrow(
654 JSFunction* caller) {
655 DisableAssertNoAllocation enable_allocation;
656 if (!caller->shared()->is_classic_mode()) {
657 return isolate->Throw(
658 *isolate->factory()->NewTypeError(
"strict_caller",
659 HandleVector<Object>(
NULL, 0)));
668 : frame_iterator_(isolate),
674 if (functions_.length() == 0)
return NULL;
675 JSFunction* next_function = functions_[index_];
680 return next_function;
689 next_function =
next();
690 if (next_function ==
function)
return true;
691 }
while (next_function !=
NULL);
696 void GetFunctions() {
697 functions_.Rewind(0);
698 if (frame_iterator_.done())
return;
701 ASSERT(functions_.length() > 0);
702 frame_iterator_.Advance();
703 index_ = functions_.length() - 1;
706 List<JSFunction*> functions_;
711 MaybeObject* Accessors::FunctionGetCaller(
Object*
object,
void*) {
712 Isolate* isolate = Isolate::Current();
713 HandleScope scope(isolate);
714 AssertNoAllocation no_alloc;
715 JSFunction* holder = FindInstanceOf<JSFunction>(object);
716 if (holder ==
NULL)
return isolate->heap()->undefined_value();
717 if (holder->shared()->native())
return isolate->heap()->null_value();
718 Handle<JSFunction>
function(holder, isolate);
720 FrameFunctionIterator it(isolate, no_alloc);
723 if (!it.Find(*
function)) {
725 return isolate->heap()->null_value();
732 if (caller ==
NULL)
return isolate->heap()->null_value();
733 }
while (caller->shared()->is_toplevel());
737 JSFunction* potential_caller = caller;
738 while (potential_caller !=
NULL && potential_caller->IsBuiltin()) {
739 caller = potential_caller;
740 potential_caller = it.next();
742 if (!caller->shared()->native() && potential_caller !=
NULL) {
743 caller = potential_caller;
748 if (caller->shared()->bound()) {
749 return isolate->heap()->null_value();
751 return CheckNonStrictCallerOrThrow(isolate, caller);
755 const AccessorDescriptor Accessors::FunctionCaller = {
767 MaybeObject* Accessors::ObjectGetPrototype(
Object* receiver,
void*) {
768 Object* current = receiver->GetPrototype();
769 while (current->IsJSObject() &&
771 current = current->GetPrototype();
777 MaybeObject* Accessors::ObjectSetPrototype(JSObject* receiver,
780 const bool skip_hidden_prototypes =
true;
782 return receiver->SetPrototype(value, skip_hidden_prototypes);
786 const AccessorDescriptor Accessors::ObjectPrototype = {
802 ASSERT(context->IsModuleContext());
803 int slot = info.
Data()->Int32Value();
804 Object* value = context->get(slot);
805 if (value->IsTheHole()) {
806 Handle<String> name = v8::Utils::OpenHandle(*property);
807 Isolate* isolate = instance->GetIsolate();
808 isolate->ScheduleThrow(
809 *isolate->factory()->NewReferenceError(
"not_defined",
817 static void ModuleSetExport(
823 ASSERT(context->IsModuleContext());
824 int slot = info.
Data()->Int32Value();
825 Object* old_value = context->get(slot);
826 if (old_value->IsTheHole()) {
827 Handle<String> name = v8::Utils::OpenHandle(*property);
828 Isolate* isolate = instance->GetIsolate();
829 isolate->ScheduleThrow(
830 *isolate->factory()->NewReferenceError(
"not_defined",
834 context->set(slot, *v8::Utils::OpenHandle(*value));
842 Factory* factory = name->GetIsolate()->factory();
844 info->set_property_attributes(attributes);
845 info->set_all_can_read(
true);
846 info->set_all_can_write(
true);
847 info->set_name(*name);
851 info->set_getter(*getter);
852 if (!(attributes &
ReadOnly)) info->set_setter(*setter);
static bool CompileLazy(Handle< JSFunction > function, ClearExceptionFlag flag)
bool Find(JSFunction *function)
static Handle< Object > ToUint32(Handle< Object > obj, bool *exc)
MUST_USE_RESULT MaybeObject * AllocateFunctionPrototype(JSFunction *function)
bool is_hidden_prototype()
static String * cast(Object *obj)
static Smi * FromInt(int value)
static Handle< T > cast(Handle< S > that)
Handle< AccessorInfo > NewAccessorInfo()
static Failure * Exception()
Object * GetExpression(int index) const
void InitScriptLineEnds(Handle< Script > script)
#define ASSERT(condition)
static Script * cast(Object *obj)
static Context * cast(Object *context)
static SharedFunctionInfo * cast(Object *obj)
Handle< JSObject > NewArgumentsObject(Handle< Object > callee, int length)
int ComputeParametersCount() const
static Smi * cast(Object *object)
Local< Object > Holder() const
Handle< JSValue > GetScriptWrapper(Handle< Script > script)
Handle< FixedArray > NewFixedArray(int size, PretenureFlag pretenure=NOT_TENURED)
static MaybeObject * FunctionGetArguments(Object *object, void *)
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
static Handle< AccessorInfo > MakeModuleExport(Handle< String > name, int index, PropertyAttributes attributes)
static MUST_USE_RESULT MaybeObject * FunctionSetPrototype(JSObject *object, Object *value, void *)
FrameFunctionIterator(Isolate *isolate, const AssertNoAllocation &promise)
JavaScriptFrameIteratorTemp< StackFrameIterator > JavaScriptFrameIterator
virtual void GetFunctions(List< JSFunction * > *functions)
static MUST_USE_RESULT MaybeObject * FunctionGetPrototype(Object *object, void *)
v8::internal::Handle< v8::internal::Object > FromCData(T obj)
static JSValue * cast(Object *obj)
static Handle< Object > ToNumber(Handle< Object > obj, bool *exc)
static FixedArray * cast(Object *obj)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
Local< Value > Data() const
Vector< Handle< Object > > HandleVector(v8::internal::Handle< T > *elms, int length)
static JSModule * cast(Object *obj)
Object * GetParameter(int index) const
static JSObject * cast(Object *obj)