| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/contexts.h" | 10 #include "src/contexts.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // | 158 // |
| 159 // Accessors::ArrayLength | 159 // Accessors::ArrayLength |
| 160 // | 160 // |
| 161 | 161 |
| 162 | 162 |
| 163 // The helper function will 'flatten' Number objects. | 163 // The helper function will 'flatten' Number objects. |
| 164 Handle<Object> Accessors::FlattenNumber(Isolate* isolate, | 164 Handle<Object> Accessors::FlattenNumber(Isolate* isolate, |
| 165 Handle<Object> value) { | 165 Handle<Object> value) { |
| 166 if (value->IsNumber() || !value->IsJSValue()) return value; | 166 if (value->IsNumber() || !value->IsJSValue()) return value; |
| 167 Handle<JSValue> wrapper = Handle<JSValue>::cast(value); | 167 Handle<JSValue> wrapper = Handle<JSValue>::cast(value); |
| 168 ASSERT(wrapper->GetIsolate()->native_context()->number_function()-> | 168 DCHECK(wrapper->GetIsolate()->native_context()->number_function()-> |
| 169 has_initial_map()); | 169 has_initial_map()); |
| 170 if (wrapper->map() == isolate->number_function()->initial_map()) { | 170 if (wrapper->map() == isolate->number_function()->initial_map()) { |
| 171 return handle(wrapper->value(), isolate); | 171 return handle(wrapper->value(), isolate); |
| 172 } | 172 } |
| 173 | 173 |
| 174 return value; | 174 return value; |
| 175 } | 175 } |
| 176 | 176 |
| 177 | 177 |
| 178 void Accessors::ArrayLengthGetter( | 178 void Accessors::ArrayLengthGetter( |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 547 |
| 548 void Accessors::ScriptLineEndsGetter( | 548 void Accessors::ScriptLineEndsGetter( |
| 549 v8::Local<v8::String> name, | 549 v8::Local<v8::String> name, |
| 550 const v8::PropertyCallbackInfo<v8::Value>& info) { | 550 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 551 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 551 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 552 HandleScope scope(isolate); | 552 HandleScope scope(isolate); |
| 553 Handle<Object> object = Utils::OpenHandle(*info.This()); | 553 Handle<Object> object = Utils::OpenHandle(*info.This()); |
| 554 Handle<Script> script( | 554 Handle<Script> script( |
| 555 Script::cast(Handle<JSValue>::cast(object)->value()), isolate); | 555 Script::cast(Handle<JSValue>::cast(object)->value()), isolate); |
| 556 Script::InitLineEnds(script); | 556 Script::InitLineEnds(script); |
| 557 ASSERT(script->line_ends()->IsFixedArray()); | 557 DCHECK(script->line_ends()->IsFixedArray()); |
| 558 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); | 558 Handle<FixedArray> line_ends(FixedArray::cast(script->line_ends())); |
| 559 // We do not want anyone to modify this array from JS. | 559 // We do not want anyone to modify this array from JS. |
| 560 ASSERT(*line_ends == isolate->heap()->empty_fixed_array() || | 560 DCHECK(*line_ends == isolate->heap()->empty_fixed_array() || |
| 561 line_ends->map() == isolate->heap()->fixed_cow_array_map()); | 561 line_ends->map() == isolate->heap()->fixed_cow_array_map()); |
| 562 Handle<JSArray> js_array = | 562 Handle<JSArray> js_array = |
| 563 isolate->factory()->NewJSArrayWithElements(line_ends); | 563 isolate->factory()->NewJSArrayWithElements(line_ends); |
| 564 info.GetReturnValue().Set(Utils::ToLocal(js_array)); | 564 info.GetReturnValue().Set(Utils::ToLocal(js_array)); |
| 565 } | 565 } |
| 566 | 566 |
| 567 | 567 |
| 568 void Accessors::ScriptLineEndsSetter( | 568 void Accessors::ScriptLineEndsSetter( |
| 569 v8::Local<v8::String> name, | 569 v8::Local<v8::String> name, |
| 570 v8::Local<v8::Value> value, | 570 v8::Local<v8::Value> value, |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 Handle<Object> old_value; | 852 Handle<Object> old_value; |
| 853 bool is_observed = function->map()->is_observed(); | 853 bool is_observed = function->map()->is_observed(); |
| 854 if (is_observed) { | 854 if (is_observed) { |
| 855 if (function->has_prototype()) | 855 if (function->has_prototype()) |
| 856 old_value = handle(function->prototype(), isolate); | 856 old_value = handle(function->prototype(), isolate); |
| 857 else | 857 else |
| 858 old_value = isolate->factory()->NewFunctionPrototype(function); | 858 old_value = isolate->factory()->NewFunctionPrototype(function); |
| 859 } | 859 } |
| 860 | 860 |
| 861 JSFunction::SetPrototype(function, value); | 861 JSFunction::SetPrototype(function, value); |
| 862 ASSERT(function->prototype() == *value); | 862 DCHECK(function->prototype() == *value); |
| 863 | 863 |
| 864 if (is_observed && !old_value->SameValue(*value)) { | 864 if (is_observed && !old_value->SameValue(*value)) { |
| 865 JSObject::EnqueueChangeRecord( | 865 JSObject::EnqueueChangeRecord( |
| 866 function, "update", isolate->factory()->prototype_string(), old_value); | 866 function, "update", isolate->factory()->prototype_string(), old_value); |
| 867 } | 867 } |
| 868 | 868 |
| 869 return function; | 869 return function; |
| 870 } | 870 } |
| 871 | 871 |
| 872 | 872 |
| 873 Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) { | 873 Handle<Object> Accessors::FunctionGetPrototype(Handle<JSFunction> function) { |
| 874 return GetFunctionPrototype(function->GetIsolate(), function); | 874 return GetFunctionPrototype(function->GetIsolate(), function); |
| 875 } | 875 } |
| 876 | 876 |
| 877 | 877 |
| 878 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function, | 878 Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function, |
| 879 Handle<Object> prototype) { | 879 Handle<Object> prototype) { |
| 880 ASSERT(function->should_have_prototype()); | 880 DCHECK(function->should_have_prototype()); |
| 881 Isolate* isolate = function->GetIsolate(); | 881 Isolate* isolate = function->GetIsolate(); |
| 882 return SetFunctionPrototype(isolate, function, prototype); | 882 return SetFunctionPrototype(isolate, function, prototype); |
| 883 } | 883 } |
| 884 | 884 |
| 885 | 885 |
| 886 void Accessors::FunctionPrototypeGetter( | 886 void Accessors::FunctionPrototypeGetter( |
| 887 v8::Local<v8::String> name, | 887 v8::Local<v8::String> name, |
| 888 const v8::PropertyCallbackInfo<v8::Value>& info) { | 888 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 889 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); | 889 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate()); |
| 890 HandleScope scope(isolate); | 890 HandleScope scope(isolate); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 frame = it.frame(); | 1088 frame = it.frame(); |
| 1089 | 1089 |
| 1090 // Get the number of arguments and construct an arguments object | 1090 // Get the number of arguments and construct an arguments object |
| 1091 // mirror for the right frame. | 1091 // mirror for the right frame. |
| 1092 const int length = frame->ComputeParametersCount(); | 1092 const int length = frame->ComputeParametersCount(); |
| 1093 Handle<JSObject> arguments = isolate->factory()->NewArgumentsObject( | 1093 Handle<JSObject> arguments = isolate->factory()->NewArgumentsObject( |
| 1094 function, length); | 1094 function, length); |
| 1095 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); | 1095 Handle<FixedArray> array = isolate->factory()->NewFixedArray(length); |
| 1096 | 1096 |
| 1097 // Copy the parameters to the arguments object. | 1097 // Copy the parameters to the arguments object. |
| 1098 ASSERT(array->length() == length); | 1098 DCHECK(array->length() == length); |
| 1099 for (int i = 0; i < length; i++) array->set(i, frame->GetParameter(i)); | 1099 for (int i = 0; i < length; i++) array->set(i, frame->GetParameter(i)); |
| 1100 arguments->set_elements(*array); | 1100 arguments->set_elements(*array); |
| 1101 | 1101 |
| 1102 // Return the freshly allocated arguments object. | 1102 // Return the freshly allocated arguments object. |
| 1103 return arguments; | 1103 return arguments; |
| 1104 } | 1104 } |
| 1105 | 1105 |
| 1106 // No frame corresponding to the given function found. Return null. | 1106 // No frame corresponding to the given function found. Return null. |
| 1107 return isolate->factory()->null_value(); | 1107 return isolate->factory()->null_value(); |
| 1108 } | 1108 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 } while (next_function != NULL); | 1189 } while (next_function != NULL); |
| 1190 return false; | 1190 return false; |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 private: | 1193 private: |
| 1194 void GetFunctions() { | 1194 void GetFunctions() { |
| 1195 functions_.Rewind(0); | 1195 functions_.Rewind(0); |
| 1196 if (frame_iterator_.done()) return; | 1196 if (frame_iterator_.done()) return; |
| 1197 JavaScriptFrame* frame = frame_iterator_.frame(); | 1197 JavaScriptFrame* frame = frame_iterator_.frame(); |
| 1198 frame->GetFunctions(&functions_); | 1198 frame->GetFunctions(&functions_); |
| 1199 ASSERT(functions_.length() > 0); | 1199 DCHECK(functions_.length() > 0); |
| 1200 frame_iterator_.Advance(); | 1200 frame_iterator_.Advance(); |
| 1201 index_ = functions_.length() - 1; | 1201 index_ = functions_.length() - 1; |
| 1202 } | 1202 } |
| 1203 Isolate* isolate_; | 1203 Isolate* isolate_; |
| 1204 JavaScriptFrameIterator frame_iterator_; | 1204 JavaScriptFrameIterator frame_iterator_; |
| 1205 List<JSFunction*> functions_; | 1205 List<JSFunction*> functions_; |
| 1206 int index_; | 1206 int index_; |
| 1207 }; | 1207 }; |
| 1208 | 1208 |
| 1209 | 1209 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 | 1297 |
| 1298 // | 1298 // |
| 1299 // Accessors::MakeModuleExport | 1299 // Accessors::MakeModuleExport |
| 1300 // | 1300 // |
| 1301 | 1301 |
| 1302 static void ModuleGetExport( | 1302 static void ModuleGetExport( |
| 1303 v8::Local<v8::String> property, | 1303 v8::Local<v8::String> property, |
| 1304 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1304 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1305 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); | 1305 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); |
| 1306 Context* context = Context::cast(instance->context()); | 1306 Context* context = Context::cast(instance->context()); |
| 1307 ASSERT(context->IsModuleContext()); | 1307 DCHECK(context->IsModuleContext()); |
| 1308 int slot = info.Data()->Int32Value(); | 1308 int slot = info.Data()->Int32Value(); |
| 1309 Object* value = context->get(slot); | 1309 Object* value = context->get(slot); |
| 1310 Isolate* isolate = instance->GetIsolate(); | 1310 Isolate* isolate = instance->GetIsolate(); |
| 1311 if (value->IsTheHole()) { | 1311 if (value->IsTheHole()) { |
| 1312 Handle<String> name = v8::Utils::OpenHandle(*property); | 1312 Handle<String> name = v8::Utils::OpenHandle(*property); |
| 1313 isolate->ScheduleThrow( | 1313 isolate->ScheduleThrow( |
| 1314 *isolate->factory()->NewReferenceError("not_defined", | 1314 *isolate->factory()->NewReferenceError("not_defined", |
| 1315 HandleVector(&name, 1))); | 1315 HandleVector(&name, 1))); |
| 1316 return; | 1316 return; |
| 1317 } | 1317 } |
| 1318 info.GetReturnValue().Set(v8::Utils::ToLocal(Handle<Object>(value, isolate))); | 1318 info.GetReturnValue().Set(v8::Utils::ToLocal(Handle<Object>(value, isolate))); |
| 1319 } | 1319 } |
| 1320 | 1320 |
| 1321 | 1321 |
| 1322 static void ModuleSetExport( | 1322 static void ModuleSetExport( |
| 1323 v8::Local<v8::String> property, | 1323 v8::Local<v8::String> property, |
| 1324 v8::Local<v8::Value> value, | 1324 v8::Local<v8::Value> value, |
| 1325 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1325 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 1326 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); | 1326 JSModule* instance = JSModule::cast(*v8::Utils::OpenHandle(*info.Holder())); |
| 1327 Context* context = Context::cast(instance->context()); | 1327 Context* context = Context::cast(instance->context()); |
| 1328 ASSERT(context->IsModuleContext()); | 1328 DCHECK(context->IsModuleContext()); |
| 1329 int slot = info.Data()->Int32Value(); | 1329 int slot = info.Data()->Int32Value(); |
| 1330 Object* old_value = context->get(slot); | 1330 Object* old_value = context->get(slot); |
| 1331 if (old_value->IsTheHole()) { | 1331 if (old_value->IsTheHole()) { |
| 1332 Handle<String> name = v8::Utils::OpenHandle(*property); | 1332 Handle<String> name = v8::Utils::OpenHandle(*property); |
| 1333 Isolate* isolate = instance->GetIsolate(); | 1333 Isolate* isolate = instance->GetIsolate(); |
| 1334 isolate->ScheduleThrow( | 1334 isolate->ScheduleThrow( |
| 1335 *isolate->factory()->NewReferenceError("not_defined", | 1335 *isolate->factory()->NewReferenceError("not_defined", |
| 1336 HandleVector(&name, 1))); | 1336 HandleVector(&name, 1))); |
| 1337 return; | 1337 return; |
| 1338 } | 1338 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1354 info->set_data(Smi::FromInt(index)); | 1354 info->set_data(Smi::FromInt(index)); |
| 1355 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); | 1355 Handle<Object> getter = v8::FromCData(isolate, &ModuleGetExport); |
| 1356 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); | 1356 Handle<Object> setter = v8::FromCData(isolate, &ModuleSetExport); |
| 1357 info->set_getter(*getter); | 1357 info->set_getter(*getter); |
| 1358 if (!(attributes & ReadOnly)) info->set_setter(*setter); | 1358 if (!(attributes & ReadOnly)) info->set_setter(*setter); |
| 1359 return info; | 1359 return info; |
| 1360 } | 1360 } |
| 1361 | 1361 |
| 1362 | 1362 |
| 1363 } } // namespace v8::internal | 1363 } } // namespace v8::internal |
| OLD | NEW |