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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 Handle<Object> privates; | 634 Handle<Object> privates; |
635 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 635 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
636 isolate, privates, Object::GetPropertyOrElement(registry, part)); | 636 isolate, privates, Object::GetPropertyOrElement(registry, part)); |
637 Handle<Object> symbol; | 637 Handle<Object> symbol; |
638 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 638 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
639 isolate, symbol, Object::GetPropertyOrElement(privates, name)); | 639 isolate, symbol, Object::GetPropertyOrElement(privates, name)); |
640 if (!symbol->IsSymbol()) { | 640 if (!symbol->IsSymbol()) { |
641 ASSERT(symbol->IsUndefined()); | 641 ASSERT(symbol->IsUndefined()); |
642 symbol = isolate->factory()->NewPrivateSymbol(); | 642 symbol = isolate->factory()->NewPrivateSymbol(); |
643 Handle<Symbol>::cast(symbol)->set_name(*name); | 643 Handle<Symbol>::cast(symbol)->set_name(*name); |
644 JSObject::SetProperty(Handle<JSObject>::cast(privates), name, symbol, NONE, | 644 JSObject::SetProperty(Handle<JSObject>::cast(privates), name, symbol, |
645 STRICT).Assert(); | 645 STRICT).Assert(); |
646 } | 646 } |
647 return *symbol; | 647 return *symbol; |
648 } | 648 } |
649 | 649 |
650 | 650 |
651 RUNTIME_FUNCTION(Runtime_NewSymbolWrapper) { | 651 RUNTIME_FUNCTION(Runtime_NewSymbolWrapper) { |
652 HandleScope scope(isolate); | 652 HandleScope scope(isolate); |
653 ASSERT(args.length() == 1); | 653 ASSERT(args.length() == 1); |
654 CONVERT_ARG_HANDLE_CHECKED(Symbol, symbol, 0); | 654 CONVERT_ARG_HANDLE_CHECKED(Symbol, symbol, 0); |
(...skipping 1566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2221 RUNTIME_ASSERT(args.length() == 3); | 2221 RUNTIME_ASSERT(args.length() == 3); |
2222 | 2222 |
2223 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 2223 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
2224 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 1); | 2224 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 1); |
2225 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 2225 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
2226 | 2226 |
2227 Handle<GlobalObject> global(isolate->context()->global_object()); | 2227 Handle<GlobalObject> global(isolate->context()->global_object()); |
2228 Handle<Object> result; | 2228 Handle<Object> result; |
2229 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 2229 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
2230 isolate, result, | 2230 isolate, result, |
2231 JSReceiver::SetProperty(global, name, value, NONE, strict_mode)); | 2231 JSReceiver::SetProperty(global, name, value, strict_mode)); |
2232 return *result; | 2232 return *result; |
2233 } | 2233 } |
2234 | 2234 |
2235 | 2235 |
2236 RUNTIME_FUNCTION(Runtime_InitializeConstGlobal) { | 2236 RUNTIME_FUNCTION(Runtime_InitializeConstGlobal) { |
2237 HandleScope handle_scope(isolate); | 2237 HandleScope handle_scope(isolate); |
2238 // All constants are declared with an initial value. The name | 2238 // All constants are declared with an initial value. The name |
2239 // of the constant is the first argument and the initial value | 2239 // of the constant is the first argument and the initial value |
2240 // is the second. | 2240 // is the second. |
2241 RUNTIME_ASSERT(args.length() == 2); | 2241 RUNTIME_ASSERT(args.length() == 2); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2543 | 2543 |
2544 static void InstallBuiltin(Isolate* isolate, | 2544 static void InstallBuiltin(Isolate* isolate, |
2545 Handle<JSObject> holder, | 2545 Handle<JSObject> holder, |
2546 const char* name, | 2546 const char* name, |
2547 Builtins::Name builtin_name) { | 2547 Builtins::Name builtin_name) { |
2548 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); | 2548 Handle<String> key = isolate->factory()->InternalizeUtf8String(name); |
2549 Handle<Code> code(isolate->builtins()->builtin(builtin_name)); | 2549 Handle<Code> code(isolate->builtins()->builtin(builtin_name)); |
2550 Handle<JSFunction> optimized = | 2550 Handle<JSFunction> optimized = |
2551 isolate->factory()->NewFunctionWithoutPrototype(key, code); | 2551 isolate->factory()->NewFunctionWithoutPrototype(key, code); |
2552 optimized->shared()->DontAdaptArguments(); | 2552 optimized->shared()->DontAdaptArguments(); |
2553 JSReceiver::SetProperty(holder, key, optimized, NONE, STRICT).Assert(); | 2553 JSObject::AddProperty(holder, key, optimized, NONE); |
2554 } | 2554 } |
2555 | 2555 |
2556 | 2556 |
2557 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { | 2557 RUNTIME_FUNCTION(Runtime_SpecialArrayFunctions) { |
2558 HandleScope scope(isolate); | 2558 HandleScope scope(isolate); |
2559 ASSERT(args.length() == 0); | 2559 ASSERT(args.length() == 0); |
2560 Handle<JSObject> holder = | 2560 Handle<JSObject> holder = |
2561 isolate->factory()->NewJSObject(isolate->object_function()); | 2561 isolate->factory()->NewJSObject(isolate->object_function()); |
2562 | 2562 |
2563 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); | 2563 InstallBuiltin(isolate, holder, "pop", Builtins::kArrayPop); |
(...skipping 2374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4938 !isolate->MayNamedAccess(js_object, name, v8::ACCESS_SET)) { | 4938 !isolate->MayNamedAccess(js_object, name, v8::ACCESS_SET)) { |
4939 return isolate->heap()->undefined_value(); | 4939 return isolate->heap()->undefined_value(); |
4940 } | 4940 } |
4941 | 4941 |
4942 LookupResult lookup(isolate); | 4942 LookupResult lookup(isolate); |
4943 js_object->LookupOwnRealNamedProperty(name, &lookup); | 4943 js_object->LookupOwnRealNamedProperty(name, &lookup); |
4944 | 4944 |
4945 // Take special care when attributes are different and there is already | 4945 // Take special care when attributes are different and there is already |
4946 // a property. For simplicity we normalize the property which enables us | 4946 // a property. For simplicity we normalize the property which enables us |
4947 // to not worry about changing the instance_descriptor and creating a new | 4947 // to not worry about changing the instance_descriptor and creating a new |
4948 // map. The current version of SetObjectProperty does not handle attributes | 4948 // map. |
4949 // correctly in the case where a property is a field and is reset with | |
4950 // new attributes. | |
4951 if (lookup.IsFound() && | 4949 if (lookup.IsFound() && |
4952 (attr != lookup.GetAttributes() || lookup.IsPropertyCallbacks())) { | 4950 (attr != lookup.GetAttributes() || lookup.IsPropertyCallbacks())) { |
4953 // New attributes - normalize to avoid writing to instance descriptor | 4951 // New attributes - normalize to avoid writing to instance descriptor |
4954 if (js_object->IsJSGlobalProxy()) { | 4952 if (js_object->IsJSGlobalProxy()) { |
4955 // Since the result is a property, the prototype will exist so | 4953 // Since the result is a property, the prototype will exist so |
4956 // we don't have to check for null. | 4954 // we don't have to check for null. |
4957 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype())); | 4955 js_object = Handle<JSObject>(JSObject::cast(js_object->GetPrototype())); |
4958 } | 4956 } |
4959 | 4957 |
4960 if (attr != lookup.GetAttributes() || | 4958 if (attr != lookup.GetAttributes() || |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4994 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 4992 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
4995 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); | 4993 CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); |
4996 return *JSObject::GetDataProperty(object, key); | 4994 return *JSObject::GetDataProperty(object, key); |
4997 } | 4995 } |
4998 | 4996 |
4999 | 4997 |
5000 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, | 4998 MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate, |
5001 Handle<Object> object, | 4999 Handle<Object> object, |
5002 Handle<Object> key, | 5000 Handle<Object> key, |
5003 Handle<Object> value, | 5001 Handle<Object> value, |
5004 StrictMode strict_mode, | 5002 StrictMode strict_mode) { |
5005 PropertyAttributes attrs) { | |
5006 if (object->IsUndefined() || object->IsNull()) { | 5003 if (object->IsUndefined() || object->IsNull()) { |
5007 Handle<Object> args[2] = { key, object }; | 5004 Handle<Object> args[2] = { key, object }; |
5008 Handle<Object> error = | 5005 Handle<Object> error = |
5009 isolate->factory()->NewTypeError("non_object_property_store", | 5006 isolate->factory()->NewTypeError("non_object_property_store", |
5010 HandleVector(args, 2)); | 5007 HandleVector(args, 2)); |
5011 return isolate->Throw<Object>(error); | 5008 return isolate->Throw<Object>(error); |
5012 } | 5009 } |
5013 | 5010 |
5014 if (object->IsJSProxy()) { | 5011 if (object->IsJSProxy()) { |
5015 Handle<Object> name_object; | 5012 Handle<Object> name_object; |
5016 if (key->IsSymbol()) { | 5013 if (key->IsSymbol()) { |
5017 name_object = key; | 5014 name_object = key; |
5018 } else { | 5015 } else { |
5019 ASSIGN_RETURN_ON_EXCEPTION( | 5016 ASSIGN_RETURN_ON_EXCEPTION( |
5020 isolate, name_object, Execution::ToString(isolate, key), Object); | 5017 isolate, name_object, Execution::ToString(isolate, key), Object); |
5021 } | 5018 } |
5022 Handle<Name> name = Handle<Name>::cast(name_object); | 5019 Handle<Name> name = Handle<Name>::cast(name_object); |
5023 return JSReceiver::SetProperty(Handle<JSProxy>::cast(object), name, value, | 5020 return JSReceiver::SetProperty(Handle<JSProxy>::cast(object), name, value, |
5024 attrs, strict_mode); | 5021 strict_mode); |
5025 } | 5022 } |
5026 | 5023 |
5027 // If the object isn't a JavaScript object, we ignore the store. | 5024 // If the object isn't a JavaScript object, we ignore the store. |
5028 if (!object->IsJSObject()) return value; | 5025 if (!object->IsJSObject()) return value; |
5029 | 5026 |
5030 Handle<JSObject> js_object = Handle<JSObject>::cast(object); | 5027 Handle<JSObject> js_object = Handle<JSObject>::cast(object); |
5031 | 5028 |
5032 // Check if the given key is an array index. | 5029 // Check if the given key is an array index. |
5033 uint32_t index; | 5030 uint32_t index; |
5034 if (key->ToArrayIndex(&index)) { | 5031 if (key->ToArrayIndex(&index)) { |
(...skipping 11 matching lines...) Expand all Loading... |
5046 JSObject::ValidateElements(js_object); | 5043 JSObject::ValidateElements(js_object); |
5047 if (js_object->HasExternalArrayElements() || | 5044 if (js_object->HasExternalArrayElements() || |
5048 js_object->HasFixedTypedArrayElements()) { | 5045 js_object->HasFixedTypedArrayElements()) { |
5049 if (!value->IsNumber() && !value->IsUndefined()) { | 5046 if (!value->IsNumber() && !value->IsUndefined()) { |
5050 ASSIGN_RETURN_ON_EXCEPTION( | 5047 ASSIGN_RETURN_ON_EXCEPTION( |
5051 isolate, value, Execution::ToNumber(isolate, value), Object); | 5048 isolate, value, Execution::ToNumber(isolate, value), Object); |
5052 } | 5049 } |
5053 } | 5050 } |
5054 | 5051 |
5055 MaybeHandle<Object> result = JSObject::SetElement( | 5052 MaybeHandle<Object> result = JSObject::SetElement( |
5056 js_object, index, value, attrs, strict_mode, true, SET_PROPERTY); | 5053 js_object, index, value, NONE, strict_mode, true, SET_PROPERTY); |
5057 JSObject::ValidateElements(js_object); | 5054 JSObject::ValidateElements(js_object); |
5058 | 5055 |
5059 return result.is_null() ? result : value; | 5056 return result.is_null() ? result : value; |
5060 } | 5057 } |
5061 | 5058 |
5062 if (key->IsName()) { | 5059 if (key->IsName()) { |
5063 Handle<Name> name = Handle<Name>::cast(key); | 5060 Handle<Name> name = Handle<Name>::cast(key); |
5064 if (name->AsArrayIndex(&index)) { | 5061 if (name->AsArrayIndex(&index)) { |
5065 if (js_object->HasExternalArrayElements()) { | 5062 if (js_object->HasExternalArrayElements()) { |
5066 if (!value->IsNumber() && !value->IsUndefined()) { | 5063 if (!value->IsNumber() && !value->IsUndefined()) { |
5067 ASSIGN_RETURN_ON_EXCEPTION( | 5064 ASSIGN_RETURN_ON_EXCEPTION( |
5068 isolate, value, Execution::ToNumber(isolate, value), Object); | 5065 isolate, value, Execution::ToNumber(isolate, value), Object); |
5069 } | 5066 } |
5070 } | 5067 } |
5071 return JSObject::SetElement(js_object, index, value, attrs, | 5068 return JSObject::SetElement(js_object, index, value, NONE, strict_mode, |
5072 strict_mode, true, SET_PROPERTY); | 5069 true, SET_PROPERTY); |
5073 } else { | 5070 } else { |
5074 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); | 5071 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); |
5075 return JSReceiver::SetProperty( | 5072 return JSReceiver::SetProperty(js_object, name, value, strict_mode); |
5076 js_object, name, value, attrs, strict_mode); | |
5077 } | 5073 } |
5078 } | 5074 } |
5079 | 5075 |
5080 // Call-back into JavaScript to convert the key to a string. | 5076 // Call-back into JavaScript to convert the key to a string. |
5081 Handle<Object> converted; | 5077 Handle<Object> converted; |
5082 ASSIGN_RETURN_ON_EXCEPTION( | 5078 ASSIGN_RETURN_ON_EXCEPTION( |
5083 isolate, converted, Execution::ToString(isolate, key), Object); | 5079 isolate, converted, Execution::ToString(isolate, key), Object); |
5084 Handle<String> name = Handle<String>::cast(converted); | 5080 Handle<String> name = Handle<String>::cast(converted); |
5085 | 5081 |
5086 if (name->AsArrayIndex(&index)) { | 5082 if (name->AsArrayIndex(&index)) { |
5087 return JSObject::SetElement(js_object, index, value, attrs, | 5083 return JSObject::SetElement(js_object, index, value, NONE, strict_mode, |
5088 strict_mode, true, SET_PROPERTY); | 5084 true, SET_PROPERTY); |
5089 } else { | 5085 } else { |
5090 return JSReceiver::SetProperty(js_object, name, value, attrs, strict_mode); | 5086 return JSReceiver::SetProperty(js_object, name, value, strict_mode); |
5091 } | 5087 } |
5092 } | 5088 } |
5093 | 5089 |
5094 | 5090 |
5095 MaybeHandle<Object> Runtime::DefineObjectProperty( | 5091 MaybeHandle<Object> Runtime::DefineObjectProperty( |
5096 Handle<JSObject> js_object, | 5092 Handle<JSObject> js_object, |
5097 Handle<Object> key, | 5093 Handle<Object> key, |
5098 Handle<Object> value, | 5094 Handle<Object> value, |
5099 PropertyAttributes attr, | 5095 PropertyAttributes attr, |
5100 JSReceiver::StoreFromKeyed store_from_keyed) { | 5096 JSReceiver::StoreFromKeyed store_from_keyed) { |
(...skipping 3853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8954 Accessors::MakeModuleExport(name, index, attr); | 8950 Accessors::MakeModuleExport(name, index, attr); |
8955 Handle<Object> result = | 8951 Handle<Object> result = |
8956 JSObject::SetAccessor(module, info).ToHandleChecked(); | 8952 JSObject::SetAccessor(module, info).ToHandleChecked(); |
8957 ASSERT(!result->IsUndefined()); | 8953 ASSERT(!result->IsUndefined()); |
8958 USE(result); | 8954 USE(result); |
8959 break; | 8955 break; |
8960 } | 8956 } |
8961 case MODULE: { | 8957 case MODULE: { |
8962 Object* referenced_context = Context::cast(host_context)->get(index); | 8958 Object* referenced_context = Context::cast(host_context)->get(index); |
8963 Handle<JSModule> value(Context::cast(referenced_context)->module()); | 8959 Handle<JSModule> value(Context::cast(referenced_context)->module()); |
8964 JSReceiver::SetProperty(module, name, value, FROZEN, STRICT).Assert(); | 8960 JSObject::SetOwnPropertyIgnoreAttributes(module, name, value, FROZEN) |
| 8961 .Assert(); |
8965 break; | 8962 break; |
8966 } | 8963 } |
8967 case INTERNAL: | 8964 case INTERNAL: |
8968 case TEMPORARY: | 8965 case TEMPORARY: |
8969 case DYNAMIC: | 8966 case DYNAMIC: |
8970 case DYNAMIC_GLOBAL: | 8967 case DYNAMIC_GLOBAL: |
8971 case DYNAMIC_LOCAL: | 8968 case DYNAMIC_LOCAL: |
8972 UNREACHABLE(); | 8969 UNREACHABLE(); |
8973 } | 8970 } |
8974 } | 8971 } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9248 // If absent in strict mode: throw. | 9245 // If absent in strict mode: throw. |
9249 Handle<Object> error = isolate->factory()->NewReferenceError( | 9246 Handle<Object> error = isolate->factory()->NewReferenceError( |
9250 "not_defined", HandleVector(&name, 1)); | 9247 "not_defined", HandleVector(&name, 1)); |
9251 return isolate->Throw(*error); | 9248 return isolate->Throw(*error); |
9252 } else { | 9249 } else { |
9253 // If absent in sloppy mode: add the property to the global object. | 9250 // If absent in sloppy mode: add the property to the global object. |
9254 object = Handle<JSReceiver>(context->global_object()); | 9251 object = Handle<JSReceiver>(context->global_object()); |
9255 } | 9252 } |
9256 | 9253 |
9257 RETURN_FAILURE_ON_EXCEPTION( | 9254 RETURN_FAILURE_ON_EXCEPTION( |
9258 isolate, JSReceiver::SetProperty(object, name, value, NONE, strict_mode)); | 9255 isolate, JSReceiver::SetProperty(object, name, value, strict_mode)); |
9259 | 9256 |
9260 return *value; | 9257 return *value; |
9261 } | 9258 } |
9262 | 9259 |
9263 | 9260 |
9264 RUNTIME_FUNCTION(Runtime_Throw) { | 9261 RUNTIME_FUNCTION(Runtime_Throw) { |
9265 HandleScope scope(isolate); | 9262 HandleScope scope(isolate); |
9266 ASSERT(args.length() == 1); | 9263 ASSERT(args.length() == 1); |
9267 | 9264 |
9268 return isolate->Throw(args[0]); | 9265 return isolate->Throw(args[0]); |
(...skipping 5690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14959 } | 14956 } |
14960 return NULL; | 14957 return NULL; |
14961 } | 14958 } |
14962 | 14959 |
14963 | 14960 |
14964 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 14961 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
14965 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 14962 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
14966 } | 14963 } |
14967 | 14964 |
14968 } } // namespace v8::internal | 14965 } } // namespace v8::internal |
OLD | NEW |