| 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/api.h" | 5 #include "src/api.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
| 8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
| 9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
| 10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
| (...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 Local<FunctionTemplate> receiver) { | 1364 Local<FunctionTemplate> receiver) { |
| 1365 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); | 1365 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); |
| 1366 } | 1366 } |
| 1367 | 1367 |
| 1368 | 1368 |
| 1369 Local<AccessorSignature> AccessorSignature::New( | 1369 Local<AccessorSignature> AccessorSignature::New( |
| 1370 Isolate* isolate, Local<FunctionTemplate> receiver) { | 1370 Isolate* isolate, Local<FunctionTemplate> receiver) { |
| 1371 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); | 1371 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); |
| 1372 } | 1372 } |
| 1373 | 1373 |
| 1374 Local<DictionarySchema> DictionarySchema::New(Isolate* v8_isolate, |
| 1375 Local<Value> keys[], |
| 1376 int keyCount) { |
| 1377 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 1378 LOG_API(isolate, DictionarySchema, New); |
| 1379 ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate); |
| 1380 i::Handle<i::DictionarySchema> schema = |
| 1381 i::DictionarySchema::New(isolate, keyCount); |
| 1382 for (int i = 0; i < keyCount; i++) { |
| 1383 i::Handle<i::Object> key = Utils::OpenHandle(*keys[i]); |
| 1384 uint32_t array_index; |
| 1385 Utils::ApiCheck(key->IsName() || key->ToArrayIndex(&array_index), |
| 1386 "v8::DictionarySchema::New", |
| 1387 "invalid dictionary key (must be name or array index)"); |
| 1388 schema->set(i, *key); |
| 1389 } |
| 1390 return Utils::ToLocal(schema); |
| 1391 } |
| 1392 |
| 1393 Maybe<bool> DictionarySchema::Get(Local<Context> context, Local<Object> object, |
| 1394 ValueFilter continue_filter, |
| 1395 Local<Value>* out, int out_length, |
| 1396 int* index) { |
| 1397 // TODO(jbroman): This is an ugly hack. |
| 1398 // We could return some V8 object (v8::Array? Something else?) that must be |
| 1399 // queried. Or we could at least wrap this up in something that doesn't |
| 1400 // require us to be a friend of v8::Local. |
| 1401 // It's also potentially quadratic at present, if everything fails the |
| 1402 // continue filter. |
| 1403 { |
| 1404 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate()); |
| 1405 for (int i = *index; i < out_length; i++) { |
| 1406 out[i] = |
| 1407 Local<Value>(reinterpret_cast<Value*>(i::HandleScope::CreateHandle( |
| 1408 isolate, isolate->heap()->undefined_value()))); |
| 1409 } |
| 1410 } |
| 1411 |
| 1412 PREPARE_FOR_EXECUTION_PRIMITIVE(context, DictionarySchema, Get, bool); |
| 1413 i::Handle<i::DictionarySchema> schema = Utils::OpenHandle(this); |
| 1414 int length = schema->length(); |
| 1415 i::Handle<i::JSReceiver> receiver = Utils::OpenHandle(*object); |
| 1416 for (; *index < length; (*index)++) { |
| 1417 i::Handle<i::Object> key(schema->get(*index), isolate); |
| 1418 bool success = false; |
| 1419 i::LookupIterator it = |
| 1420 i::LookupIterator::PropertyOrElement(isolate, receiver, key, &success); |
| 1421 CHECK(success); |
| 1422 i::Handle<i::Object> value; |
| 1423 if (!i::Object::GetProperty(&it).ToHandle(&value)) { |
| 1424 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 1425 } |
| 1426 |
| 1427 // TODO(jbroman): Hack to escape the handle scope. |
| 1428 Value* slot = out[*index].val_; |
| 1429 *reinterpret_cast<i::Object**>(slot) = *value; |
| 1430 |
| 1431 const bool should_pause = |
| 1432 (value->IsPrimitive() && !(continue_filter & kValueFilterPrimitives)) || |
| 1433 (value->IsJSReceiver() && !(continue_filter & kValueFilterObjects)); |
| 1434 if (should_pause) { |
| 1435 (*index)++; |
| 1436 return Just(false); |
| 1437 } |
| 1438 } |
| 1439 |
| 1440 return Just(true); |
| 1441 } |
| 1374 | 1442 |
| 1375 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ | 1443 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ |
| 1376 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ | 1444 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ |
| 1377 (obj)->setter(*foreign); \ | 1445 (obj)->setter(*foreign); \ |
| 1378 } while (false) | 1446 } while (false) |
| 1379 | 1447 |
| 1380 void FunctionTemplate::SetCallHandler(FunctionCallback callback, | 1448 void FunctionTemplate::SetCallHandler(FunctionCallback callback, |
| 1381 v8::Local<Value> data) { | 1449 v8::Local<Value> data) { |
| 1382 auto info = Utils::OpenHandle(this); | 1450 auto info = Utils::OpenHandle(this); |
| 1383 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); | 1451 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); |
| (...skipping 8861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10245 Address callback_address = | 10313 Address callback_address = |
| 10246 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10314 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 10247 VMState<EXTERNAL> state(isolate); | 10315 VMState<EXTERNAL> state(isolate); |
| 10248 ExternalCallbackScope call_scope(isolate, callback_address); | 10316 ExternalCallbackScope call_scope(isolate, callback_address); |
| 10249 callback(info); | 10317 callback(info); |
| 10250 } | 10318 } |
| 10251 | 10319 |
| 10252 | 10320 |
| 10253 } // namespace internal | 10321 } // namespace internal |
| 10254 } // namespace v8 | 10322 } // namespace v8 |
| OLD | NEW |