OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2012 Ericsson AB. All rights reserved. | 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 // It will not call ToString() on the v8::Value. If you want ToString() to be ca lled, | 390 // It will not call ToString() on the v8::Value. If you want ToString() to be ca lled, |
391 // please use the TONATIVE_FOR_V8STRINGRESOURCE_*() macros instead. | 391 // please use the TONATIVE_FOR_V8STRINGRESOURCE_*() macros instead. |
392 inline String toCoreStringWithUndefinedOrNullCheck(v8::Local<v8::Value> value) | 392 inline String toCoreStringWithUndefinedOrNullCheck(v8::Local<v8::Value> value) |
393 { | 393 { |
394 if (value.IsEmpty() || !value->IsString()) | 394 if (value.IsEmpty() || !value->IsString()) |
395 return String(); | 395 return String(); |
396 return toCoreString(value.As<v8::String>()); | 396 return toCoreString(value.As<v8::String>()); |
397 } | 397 } |
398 | 398 |
399 // Convert a string to a V8 string. | 399 // Convert a string to a V8 string. |
400 // Return a V8 external string that shares the underlying buffer with the given | 400 |
401 // WebCore string. The reference counting mechanism is used to keep the | 401 inline v8::Local<v8::String> v8String(v8::Isolate* isolate, const StringView& st ring) |
402 // underlying buffer alive while the string is still live in the V8 engine. | |
403 inline v8::Local<v8::String> v8String(v8::Isolate* isolate, const String& string ) | |
404 { | 402 { |
403 DCHECK(isolate); | |
405 if (string.isNull()) | 404 if (string.isNull()) |
406 return v8::String::Empty(isolate); | 405 return v8::String::Empty(isolate); |
407 return V8PerIsolateData::from(isolate)->getStringCache()->v8ExternalString(i solate, string.impl()); | 406 if (StringImpl* impl = string.sharedImpl()) |
407 return V8PerIsolateData::from(isolate)->getStringCache()->v8ExternalStri ng(isolate, impl); | |
408 if (string.is8Bit()) | |
409 return v8::String::NewFromOneByte(isolate, reinterpret_cast<const uint8_ t*>(string.characters8()), v8::NewStringType::kNormal, static_cast<int>(string.l ength())).ToLocalChecked(); | |
haraken
2016/08/27 01:21:46
Don't you want to use:
V8PerIsolateData::from(i
esprehn
2016/08/27 02:18:57
Hmm? There's no such thing as string.impl() on a S
esprehn
2016/08/27 02:24:03
ex.
https://cs.chromium.org/chromium/src/third_p
| |
410 return v8::String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*> (string.characters16()), v8::NewStringType::kNormal, static_cast<int>(string.len gth())).ToLocalChecked(); | |
408 } | 411 } |
409 | 412 |
410 inline v8::Local<v8::Value> v8StringOrNull(v8::Isolate* isolate, const AtomicStr ing& string) | 413 inline v8::Local<v8::Value> v8StringOrNull(v8::Isolate* isolate, const AtomicStr ing& string) |
411 { | 414 { |
412 if (string.isNull()) | 415 if (string.isNull()) |
413 return v8::Null(isolate); | 416 return v8::Null(isolate); |
414 return V8PerIsolateData::from(isolate)->getStringCache()->v8ExternalString(i solate, string.impl()); | 417 return V8PerIsolateData::from(isolate)->getStringCache()->v8ExternalString(i solate, string.impl()); |
415 } | 418 } |
416 | 419 |
417 inline v8::Local<v8::String> v8AtomicString(v8::Isolate* isolate, const StringVi ew& string) | 420 inline v8::Local<v8::String> v8AtomicString(v8::Isolate* isolate, const StringVi ew& string) |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
959 typedef void (*InstallTemplateFunction)(v8::Isolate*, const DOMWrapperWorld&, v8 ::Local<v8::FunctionTemplate> interfaceTemplate); | 962 typedef void (*InstallTemplateFunction)(v8::Isolate*, const DOMWrapperWorld&, v8 ::Local<v8::FunctionTemplate> interfaceTemplate); |
960 | 963 |
961 // Freeze a V8 object. The type of the first parameter and the return value is | 964 // Freeze a V8 object. The type of the first parameter and the return value is |
962 // intentionally v8::Value so that this function can wrap toV8(). | 965 // intentionally v8::Value so that this function can wrap toV8(). |
963 // If the argument isn't an object, this will crash. | 966 // If the argument isn't an object, this will crash. |
964 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, v8::Isolat e*); | 967 CORE_EXPORT v8::Local<v8::Value> freezeV8Object(v8::Local<v8::Value>, v8::Isolat e*); |
965 | 968 |
966 } // namespace blink | 969 } // namespace blink |
967 | 970 |
968 #endif // V8Binding_h | 971 #endif // V8Binding_h |
OLD | NEW |