Revert "[cleanup] Reland: Remove deprecated functions"

This reverts commit c8376b0069.

Reason for revert: Still borked: https://ci.chromium.org/p/chromium/builders/luci.chromium.try/cast_shell_linux/114796

Original change's description:
> [cleanup] Reland: Remove deprecated functions
> 
> This is reland of https://chromium-review.googlesource.com/c/v8/v8/+/1154915
> with no changes since the break in chromium for ChromeOS is now fixed.
> 
> Removes all V8_DEPRECATED functions that weren't recently marked as well
> any V8_DEPRECATE_SOON function that relied on using using the address of
> an object to get hold of the Isolate.
> 
> Bug: v8:7786
> Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;luci.chromium.try:linux-chromeos-dbg;luci.chromium.try:linux-chromeos-rel
> Change-Id: Ib62d38b9201fd0dab719948cb5ae5a0a164f7013
> Reviewed-on: https://chromium-review.googlesource.com/1172350
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Commit-Queue: Dan Elphick <delphick@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#55119}

TBR=yangguo@chromium.org,delphick@chromium.org

Change-Id: Id1308a694092acfc90a3e7183d66c002feb63999
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:7786
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;luci.chromium.try:linux-chromeos-dbg;luci.chromium.try:linux-chromeos-rel
Reviewed-on: https://chromium-review.googlesource.com/1174751
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55127}
This commit is contained in:
Leszek Swirski 2018-08-14 15:19:01 +00:00 committed by Commit Bot
parent d59deab5c7
commit 717b93852b
4 changed files with 615 additions and 2 deletions

View File

@ -1125,6 +1125,10 @@ class V8_EXPORT PrimitiveArray {
int Length() const;
void Set(Isolate* isolate, int index, Local<Primitive> item);
Local<Primitive> Get(Isolate* isolate, int index);
V8_DEPRECATE_SOON("Use Isolate version",
void Set(int index, Local<Primitive> item));
V8_DEPRECATE_SOON("Use Isolate version", Local<Primitive> Get(int index));
};
/**
@ -1352,15 +1356,23 @@ class V8_EXPORT Script {
/**
* A shorthand for ScriptCompiler::Compile().
*/
static V8_DEPRECATED("Use maybe version",
Local<Script> Compile(Local<String> source,
ScriptOrigin* origin = nullptr));
static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
Local<Context> context, Local<String> source,
ScriptOrigin* origin = nullptr);
static Local<Script> V8_DEPRECATED("Use maybe version",
Compile(Local<String> source,
Local<String> file_name));
/**
* Runs the script returning the resulting value. It will be run in the
* context in which it was created (ScriptCompiler::CompileBound or
* UnboundScript::BindToCurrentContext()).
*/
V8_DEPRECATED("Use maybe version", Local<Value> Run());
V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
/**
@ -1676,6 +1688,13 @@ class V8_EXPORT ScriptCompiler {
* It is possible to specify multiple context extensions (obj in the above
* example).
*/
static V8_DEPRECATED("Use maybe version",
Local<Function> CompileFunctionInContext(
Isolate* isolate, Source* source,
Local<Context> context, size_t arguments_count,
Local<String> arguments[],
size_t context_extension_count,
Local<Object> context_extensions[]));
static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
Local<Context> context, Source* source, size_t arguments_count,
Local<String> arguments[], size_t context_extension_count,
@ -1698,6 +1717,10 @@ class V8_EXPORT ScriptCompiler {
static CachedData* CreateCodeCache(
Local<UnboundModuleScript> unbound_module_script);
V8_DEPRECATED("Source string is no longer required",
static CachedData* CreateCodeCache(
Local<UnboundScript> unbound_script, Local<String> source));
/**
* Creates and returns code cache for the specified function that was
* previously produced by CompileFunctionInContext.
@ -1706,6 +1729,10 @@ class V8_EXPORT ScriptCompiler {
*/
static CachedData* CreateCodeCacheForFunction(Local<Function> function);
V8_DEPRECATED("Source string is no longer required",
static CachedData* CreateCodeCacheForFunction(
Local<Function> function, Local<String> source));
private:
static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
Isolate* isolate, Source* source, CompileOptions options,
@ -1725,6 +1752,7 @@ class V8_EXPORT Message {
*/
Isolate* GetIsolate() const;
V8_DEPRECATED("Use maybe version", Local<String> GetSourceLine() const);
V8_WARN_UNUSED_RESULT MaybeLocal<String> GetSourceLine(
Local<Context> context) const;
@ -1750,6 +1778,7 @@ class V8_EXPORT Message {
/**
* Returns the number, 1-based, of the line where the error occurred.
*/
V8_DEPRECATED("Use maybe version", int GetLineNumber() const);
V8_WARN_UNUSED_RESULT Maybe<int> GetLineNumber(Local<Context> context) const;
/**
@ -1829,6 +1858,8 @@ class V8_EXPORT StackTrace {
/**
* Returns a StackFrame at a particular index.
*/
V8_DEPRECATE_SOON("Use Isolate version",
Local<StackFrame> GetFrame(uint32_t index) const);
Local<StackFrame> GetFrame(Isolate* isolate, uint32_t index) const;
/**
@ -2537,6 +2568,13 @@ class V8_EXPORT Value : public Data {
V8_DEPRECATE_SOON("Use maybe version",
Local<Int32> ToInt32(Isolate* isolate) const);
inline V8_DEPRECATE_SOON("Use maybe version",
Local<Boolean> ToBoolean() const);
inline V8_DEPRECATE_SOON("Use maybe version", Local<String> ToString() const);
inline V8_DEPRECATE_SOON("Use maybe version", Local<Object> ToObject() const);
inline V8_DEPRECATE_SOON("Use maybe version",
Local<Integer> ToInteger() const);
/**
* Attempts to convert a string to an array index.
* Returns an empty handle if the conversion fails.
@ -2552,7 +2590,14 @@ class V8_EXPORT Value : public Data {
Local<Context> context) const;
V8_WARN_UNUSED_RESULT Maybe<int32_t> Int32Value(Local<Context> context) const;
V8_DEPRECATE_SOON("Use maybe version", bool BooleanValue() const);
V8_DEPRECATE_SOON("Use maybe version", double NumberValue() const);
V8_DEPRECATE_SOON("Use maybe version", int64_t IntegerValue() const);
V8_DEPRECATE_SOON("Use maybe version", uint32_t Uint32Value() const);
V8_DEPRECATE_SOON("Use maybe version", int32_t Int32Value() const);
/** JS == */
V8_DEPRECATE_SOON("Use maybe version", bool Equals(Local<Value> that) const);
V8_WARN_UNUSED_RESULT Maybe<bool> Equals(Local<Context> context,
Local<Value> that) const;
bool StrictEquals(Local<Value> that) const;
@ -2659,6 +2704,8 @@ class V8_EXPORT String : public Name {
* Returns the number of bytes in the UTF-8 encoded
* representation of this string.
*/
V8_DEPRECATE_SOON("Use Isolate version instead", int Utf8Length() const);
int Utf8Length(Isolate* isolate) const;
/**
@ -2715,12 +2762,23 @@ class V8_EXPORT String : public Name {
// 16-bit character codes.
int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1,
int options = NO_OPTIONS) const;
V8_DEPRECATE_SOON("Use Isolate* version",
int Write(uint16_t* buffer, int start = 0, int length = -1,
int options = NO_OPTIONS) const);
// One byte characters.
int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0,
int length = -1, int options = NO_OPTIONS) const;
V8_DEPRECATE_SOON("Use Isolate* version",
int WriteOneByte(uint8_t* buffer, int start = 0,
int length = -1, int options = NO_OPTIONS)
const);
// UTF-8 encoded characters.
int WriteUtf8(Isolate* isolate, char* buffer, int length = -1,
int* nchars_ref = NULL, int options = NO_OPTIONS) const;
V8_DEPRECATE_SOON("Use Isolate* version",
int WriteUtf8(char* buffer, int length = -1,
int* nchars_ref = NULL,
int options = NO_OPTIONS) const);
/**
* A zero length string.
@ -2884,6 +2942,9 @@ class V8_EXPORT String : public Name {
*/
static Local<String> Concat(Isolate* isolate, Local<String> left,
Local<String> right);
static V8_DEPRECATE_SOON("Use Isolate* version",
Local<String> Concat(Local<String> left,
Local<String> right));
/**
* Creates a new external string using the data defined in the given
@ -2952,6 +3013,8 @@ class V8_EXPORT String : public Name {
*/
class V8_EXPORT Utf8Value {
public:
V8_DEPRECATED("Use Isolate version",
explicit Utf8Value(Local<v8::Value> obj));
Utf8Value(Isolate* isolate, Local<v8::Value> obj);
~Utf8Value();
char* operator*() { return str_; }
@ -2975,6 +3038,7 @@ class V8_EXPORT String : public Name {
*/
class V8_EXPORT Value {
public:
V8_DEPRECATED("Use Isolate version", explicit Value(Local<v8::Value> obj));
Value(Isolate* isolate, Local<v8::Value> obj);
~Value();
uint16_t* operator*() { return str_; }
@ -4156,6 +4220,8 @@ class V8_EXPORT Promise : public Object {
/**
* Create a new resolver, along with an associated promise in pending state.
*/
static V8_DEPRECATED("Use maybe version",
Local<Resolver> New(Isolate* isolate));
static V8_WARN_UNUSED_RESULT MaybeLocal<Resolver> New(
Local<Context> context);
@ -4168,9 +4234,11 @@ class V8_EXPORT Promise : public Object {
* Resolve/reject the associated promise with a given value.
* Ignored if the promise is no longer pending.
*/
V8_DEPRECATED("Use maybe version", void Resolve(Local<Value> value));
V8_WARN_UNUSED_RESULT Maybe<bool> Resolve(Local<Context> context,
Local<Value> value);
V8_DEPRECATED("Use maybe version", void Reject(Local<Value> value));
V8_WARN_UNUSED_RESULT Maybe<bool> Reject(Local<Context> context,
Local<Value> value);
@ -5191,6 +5259,8 @@ class V8_EXPORT BooleanObject : public Object {
class V8_EXPORT StringObject : public Object {
public:
static Local<Value> New(Isolate* isolate, Local<String> value);
static V8_DEPRECATE_SOON("Use Isolate* version",
Local<Value> New(Local<String> value));
Local<String> ValueOf() const;
@ -5246,6 +5316,8 @@ class V8_EXPORT RegExp : public Object {
* static_cast<RegExp::Flags>(kGlobal | kMultiline))
* is equivalent to evaluating "/foo/gm".
*/
static V8_DEPRECATED("Use maybe version",
Local<RegExp> New(Local<String> pattern, Flags flags));
static V8_WARN_UNUSED_RESULT MaybeLocal<RegExp> New(Local<Context> context,
Local<String> pattern,
Flags flags);
@ -5389,8 +5461,57 @@ class V8_EXPORT Template : public Data {
friend class FunctionTemplate;
};
// TODO(dcarney): Replace GenericNamedPropertyFooCallback with just
// NamedPropertyFooCallback.
/**
* NamedProperty[Getter|Setter] are used as interceptors on object.
* See ObjectTemplate::SetNamedPropertyHandler.
*/
typedef void (*NamedPropertyGetterCallback)(
Local<String> property,
const PropertyCallbackInfo<Value>& info);
/**
* Returns the value if the setter intercepts the request.
* Otherwise, returns an empty handle.
*/
typedef void (*NamedPropertySetterCallback)(
Local<String> property,
Local<Value> value,
const PropertyCallbackInfo<Value>& info);
/**
* Returns a non-empty handle if the interceptor intercepts the request.
* The result is an integer encoding property attributes (like v8::None,
* v8::DontEnum, etc.)
*/
typedef void (*NamedPropertyQueryCallback)(
Local<String> property,
const PropertyCallbackInfo<Integer>& info);
/**
* Returns a non-empty handle if the deleter intercepts the request.
* The return value is true if the property could be deleted and false
* otherwise.
*/
typedef void (*NamedPropertyDeleterCallback)(
Local<String> property,
const PropertyCallbackInfo<Boolean>& info);
/**
* Returns an array containing the names of the properties the named
* property getter intercepts.
*
* Note: The values in the array must be of type v8::Name.
*/
typedef void (*NamedPropertyEnumeratorCallback)(
const PropertyCallbackInfo<Array>& info);
// TODO(dcarney): Deprecate and remove previous typedefs, and replace
// GenericNamedPropertyFooCallback with just NamedPropertyFooCallback.
/**
* Interceptor for get requests on an object.
@ -6057,6 +6178,39 @@ class V8_EXPORT ObjectTemplate : public Template {
Local<AccessorSignature> signature = Local<AccessorSignature>(),
SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);
/**
* Sets a named property handler on the object template.
*
* Whenever a property whose name is a string is accessed on objects created
* from this object template, the provided callback is invoked instead of
* accessing the property directly on the JavaScript object.
*
* SetNamedPropertyHandler() is different from SetHandler(), in
* that the latter can intercept symbol-named properties as well as
* string-named properties when called with a
* NamedPropertyHandlerConfiguration. New code should use SetHandler().
*
* \param getter The callback to invoke when getting a property.
* \param setter The callback to invoke when setting a property.
* \param query The callback to invoke to check if a property is present,
* and if present, get its attributes.
* \param deleter The callback to invoke when deleting a property.
* \param enumerator The callback to invoke to enumerate all the named
* properties of an object.
* \param data A piece of data that will be passed to the callbacks
* whenever they are invoked.
*/
V8_DEPRECATED(
"Use SetHandler(const NamedPropertyHandlerConfiguration) "
"with the kOnlyInterceptStrings flag set.",
void SetNamedPropertyHandler(
NamedPropertyGetterCallback getter,
NamedPropertySetterCallback setter = 0,
NamedPropertyQueryCallback query = 0,
NamedPropertyDeleterCallback deleter = 0,
NamedPropertyEnumeratorCallback enumerator = 0,
Local<Value> data = Local<Value>()));
/**
* Sets a named property handler on the object template.
*
@ -6439,6 +6593,7 @@ typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
// --- Enter/Leave Script Callback ---
typedef void (*BeforeCallEnteredCallback)(Isolate*);
typedef void (*CallCompletedCallback)(Isolate*);
typedef void (*DeprecatedCallCompletedCallback)();
/**
* HostImportModuleDynamicallyCallback is called when we require the
@ -7611,6 +7766,16 @@ class V8_EXPORT Isolate {
*/
Local<Context> GetCurrentContext();
/**
* Returns the context of the calling JavaScript code. That is the
* context of the top-most JavaScript frame. If there are no
* JavaScript frames an empty handle is returned.
*/
V8_DEPRECATED(
"Calling context concept is not compatible with tail calls, and will be "
"removed.",
Local<Context> GetCallingContext());
/** Returns the last context entered through V8's C++ API. */
Local<Context> GetEnteredContext();
@ -7862,11 +8027,17 @@ class V8_EXPORT Isolate {
* further callbacks.
*/
void AddCallCompletedCallback(CallCompletedCallback callback);
V8_DEPRECATED(
"Use callback with parameter",
void AddCallCompletedCallback(DeprecatedCallCompletedCallback callback));
/**
* Removes callback that was installed by AddCallCompletedCallback.
*/
void RemoveCallCompletedCallback(CallCompletedCallback callback);
V8_DEPRECATED("Use callback with parameter",
void RemoveCallCompletedCallback(
DeprecatedCallCompletedCallback callback));
/**
* Set the PromiseHook callback for various promise lifecycle
@ -7900,11 +8071,14 @@ class V8_EXPORT Isolate {
* Controls how Microtasks are invoked. See MicrotasksPolicy for details.
*/
void SetMicrotasksPolicy(MicrotasksPolicy policy);
V8_DEPRECATED("Use SetMicrotasksPolicy",
void SetAutorunMicrotasks(bool autorun));
/**
* Returns the policy controlling how Microtasks are invoked.
*/
MicrotasksPolicy GetMicrotasksPolicy() const;
V8_DEPRECATED("Use GetMicrotasksPolicy", bool WillAutorunMicrotasks() const);
/**
* Adds a callback to notify the host application after
@ -8293,6 +8467,28 @@ class V8_EXPORT V8 {
static void SetNativesDataBlob(StartupData* startup_blob);
static void SetSnapshotDataBlob(StartupData* startup_blob);
/**
* Bootstrap an isolate and a context from scratch to create a startup
* snapshot. Include the side-effects of running the optional script.
* Returns { NULL, 0 } on failure.
* The caller acquires ownership of the data array in the return value.
*/
V8_DEPRECATED("Use SnapshotCreator",
static StartupData CreateSnapshotDataBlob(
const char* embedded_source = NULL));
/**
* Bootstrap an isolate and a context from the cold startup blob, run the
* warm-up script to trigger code compilation. The side effects are then
* discarded. The resulting startup snapshot will include compiled code.
* Returns { NULL, 0 } on failure.
* The caller acquires ownership of the data array in the return value.
* The argument startup blob is untouched.
*/
V8_DEPRECATED("Use SnapshotCreator",
static StartupData WarmUpSnapshotDataBlob(
StartupData cold_startup_blob, const char* warmup_source));
/** Set the callback to invoke in case of Dcheck failures. */
static void SetDcheckErrorHandler(DcheckErrorCallback that);
@ -8760,6 +8956,7 @@ class V8_EXPORT TryCatch {
* Returns the .stack property of the thrown object. If no .stack
* property is present an empty handle is returned.
*/
V8_DEPRECATED("Use maybe version.", Local<Value> StackTrace() const);
V8_WARN_UNUSED_RESULT MaybeLocal<Value> StackTrace(
Local<Context> context) const;
@ -10124,6 +10321,30 @@ template <class T> Value* Value::Cast(T* value) {
}
Local<Boolean> Value::ToBoolean() const {
return ToBoolean(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(Local<Boolean>());
}
Local<String> Value::ToString() const {
return ToString(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(Local<String>());
}
Local<Object> Value::ToObject() const {
return ToObject(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(Local<Object>());
}
Local<Integer> Value::ToInteger() const {
return ToInteger(Isolate::GetCurrent()->GetCurrentContext())
.FromMaybe(Local<Integer>());
}
Boolean* Boolean::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);

View File

@ -218,6 +218,28 @@ Local<Context> ContextFromNeverReadOnlySpaceObject(
return reinterpret_cast<v8::Isolate*>(obj->GetIsolate())->GetCurrentContext();
}
// TODO(delphick): Remove this completely when the deprecated functions that use
// it are removed.
// DO NOT USE THIS IN NEW CODE!
i::Isolate* UnsafeIsolateFromHeapObject(i::Handle<i::HeapObject> obj) {
// Use MemoryChunk directly instead of Isolate::FromWritableHeapObject to
// temporarily allow isolate access from read-only space objects.
i::MemoryChunk* chunk = i::MemoryChunk::FromHeapObject(*obj);
return chunk->heap()->isolate();
}
// TODO(delphick): Remove this completely when the deprecated functions that use
// it are removed.
// DO NOT USE THIS IN NEW CODE!
Local<Context> UnsafeContextFromHeapObject(i::Handle<i::Object> obj) {
// Use MemoryChunk directly instead of Isolate::FromWritableHeapObject to
// temporarily allow isolate access from read-only space objects.
i::MemoryChunk* chunk =
i::MemoryChunk::FromHeapObject(i::HeapObject::cast(*obj));
return reinterpret_cast<Isolate*>(chunk->heap()->isolate())
->GetCurrentContext();
}
class InternalEscapableScope : public v8::EscapableHandleScope {
public:
explicit inline InternalEscapableScope(i::Isolate* isolate)
@ -514,6 +536,34 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
void Free(void* data, size_t) override { free(data); }
};
bool RunExtraCode(Isolate* isolate, Local<Context> context,
const char* utf8_source, const char* name) {
base::ElapsedTimer timer;
timer.Start();
Context::Scope context_scope(context);
TryCatch try_catch(isolate);
Local<String> source_string;
if (!String::NewFromUtf8(isolate, utf8_source, NewStringType::kNormal)
.ToLocal(&source_string)) {
return false;
}
Local<String> resource_name =
String::NewFromUtf8(isolate, name, NewStringType::kNormal)
.ToLocalChecked();
ScriptOrigin origin(resource_name);
ScriptCompiler::Source source(source_string, origin);
Local<Script> script;
if (!ScriptCompiler::Compile(context, &source).ToLocal(&script)) return false;
if (script->Run(context).IsEmpty()) return false;
if (i::FLAG_profile_deserialization) {
i::PrintF("Executing custom snapshot script %s took %0.3f ms\n", name,
timer.Elapsed().InMillisecondsF());
}
timer.Stop();
CHECK(!try_catch.HasCaught());
return true;
}
struct SnapshotCreatorData {
explicit SnapshotCreatorData(Isolate* isolate)
: isolate_(isolate),
@ -836,6 +886,77 @@ StartupData SnapshotCreator::CreateBlob(
return result;
}
StartupData V8::CreateSnapshotDataBlob(const char* embedded_source) {
// Create a new isolate and a new context from scratch, optionally run
// a script to embed, and serialize to create a snapshot blob.
StartupData result = {nullptr, 0};
base::ElapsedTimer timer;
timer.Start();
{
SnapshotCreator snapshot_creator;
Isolate* isolate = snapshot_creator.GetIsolate();
{
HandleScope scope(isolate);
Local<Context> context = Context::New(isolate);
if (embedded_source != nullptr &&
!RunExtraCode(isolate, context, embedded_source, "<embedded>")) {
return result;
}
snapshot_creator.SetDefaultContext(context);
}
result = snapshot_creator.CreateBlob(
SnapshotCreator::FunctionCodeHandling::kClear);
}
if (i::FLAG_profile_deserialization) {
i::PrintF("Creating snapshot took %0.3f ms\n",
timer.Elapsed().InMillisecondsF());
}
timer.Stop();
return result;
}
StartupData V8::WarmUpSnapshotDataBlob(StartupData cold_snapshot_blob,
const char* warmup_source) {
CHECK(cold_snapshot_blob.raw_size > 0 && cold_snapshot_blob.data != nullptr);
CHECK_NOT_NULL(warmup_source);
// Use following steps to create a warmed up snapshot blob from a cold one:
// - Create a new isolate from the cold snapshot.
// - Create a new context to run the warmup script. This will trigger
// compilation of executed functions.
// - Create a new context. This context will be unpolluted.
// - Serialize the isolate and the second context into a new snapshot blob.
StartupData result = {nullptr, 0};
base::ElapsedTimer timer;
timer.Start();
{
SnapshotCreator snapshot_creator(nullptr, &cold_snapshot_blob);
Isolate* isolate = snapshot_creator.GetIsolate();
{
HandleScope scope(isolate);
Local<Context> context = Context::New(isolate);
if (!RunExtraCode(isolate, context, warmup_source, "<warm-up>")) {
return result;
}
}
{
HandleScope handle_scope(isolate);
isolate->ContextDisposedNotification(false);
Local<Context> context = Context::New(isolate);
snapshot_creator.SetDefaultContext(context);
}
result = snapshot_creator.CreateBlob(
SnapshotCreator::FunctionCodeHandling::kKeep);
}
if (i::FLAG_profile_deserialization) {
i::PrintF("Warming up snapshot took %0.3f ms\n",
timer.Elapsed().InMillisecondsF());
}
timer.Stop();
return result;
}
void V8::SetDcheckErrorHandler(DcheckErrorCallback that) {
v8::base::SetDcheckFunction(that);
}
@ -1838,6 +1959,16 @@ static void ObjectTemplateSetNamedPropertyHandler(
cons->set_named_property_handler(*obj);
}
// TODO(cbruni) deprecate.
void ObjectTemplate::SetNamedPropertyHandler(
NamedPropertyGetterCallback getter, NamedPropertySetterCallback setter,
NamedPropertyQueryCallback query, NamedPropertyDeleterCallback remover,
NamedPropertyEnumeratorCallback enumerator, Local<Value> data) {
ObjectTemplateSetNamedPropertyHandler(
this, getter, setter, query, nullptr, remover, enumerator, nullptr, data,
PropertyHandlerFlags::kOnlyInterceptStrings);
}
void ObjectTemplate::SetHandler(
const NamedPropertyHandlerConfiguration& config) {
ObjectTemplateSetNamedPropertyHandler(
@ -2122,6 +2253,15 @@ MaybeLocal<Value> Script::Run(Local<Context> context) {
}
Local<Value> Script::Run() {
auto self = Utils::OpenHandle(this, true);
// If execution is terminating, Compile(..)->Run() requires this
// check.
if (self.is_null()) return Local<Value>();
auto context = ContextFromNeverReadOnlySpaceObject(self);
RETURN_TO_LOCAL_UNCHECKED(Run(context), Value);
}
Local<Value> ScriptOrModule::GetResourceName() {
i::Handle<i::Script> obj = Utils::OpenHandle(this);
i::Isolate* isolate = obj->GetIsolate();
@ -2173,6 +2313,12 @@ void PrimitiveArray::Set(Isolate* v8_isolate, int index,
array->set(index, *i_item);
}
void PrimitiveArray::Set(int index, Local<Primitive> item) {
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(array);
Set(reinterpret_cast<Isolate*>(isolate), index, item);
}
Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
@ -2185,6 +2331,12 @@ Local<Primitive> PrimitiveArray::Get(Isolate* v8_isolate, int index) {
return ToApiHandle<Primitive>(i_item);
}
Local<Primitive> PrimitiveArray::Get(int index) {
i::Handle<i::FixedArray> array = Utils::OpenHandle(this);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(array);
return Get(reinterpret_cast<Isolate*>(isolate), index);
}
Module::Status Module::GetStatus() const {
i::Handle<i::Module> self = Utils::OpenHandle(this);
switch (self->status()) {
@ -2530,6 +2682,17 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
}
Local<Function> ScriptCompiler::CompileFunctionInContext(
Isolate* v8_isolate, Source* source, Local<Context> v8_context,
size_t arguments_count, Local<String> arguments[],
size_t context_extension_count, Local<Object> context_extensions[]) {
RETURN_TO_LOCAL_UNCHECKED(
CompileFunctionInContext(v8_context, source, arguments_count, arguments,
context_extension_count, context_extensions),
Function);
}
ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript(
Isolate* v8_isolate, StreamedSource* source, CompileOptions options) {
if (!i::FLAG_script_streaming) {
@ -2582,6 +2745,11 @@ uint32_t ScriptCompiler::CachedDataVersionTag() {
static_cast<uint32_t>(internal::CpuFeatures::SupportedFeatures())));
}
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
Local<UnboundScript> unbound_script, Local<String> source) {
return CreateCodeCache(unbound_script);
}
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
Local<UnboundScript> unbound_script) {
i::Handle<i::SharedFunctionInfo> shared =
@ -2601,6 +2769,11 @@ ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(
return i::CodeSerializer::Serialize(shared);
}
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
Local<Function> function, Local<String> source) {
return CreateCodeCacheForFunction(function);
}
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCacheForFunction(
Local<Function> function) {
auto js_function =
@ -2622,6 +2795,23 @@ MaybeLocal<Script> Script::Compile(Local<Context> context, Local<String> source,
}
Local<Script> Script::Compile(v8::Local<String> source,
v8::ScriptOrigin* origin) {
auto str = Utils::OpenHandle(*source);
auto context = UnsafeContextFromHeapObject(str);
RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, origin), Script);
}
Local<Script> Script::Compile(v8::Local<String> source,
v8::Local<String> file_name) {
auto str = Utils::OpenHandle(*source);
auto context = UnsafeContextFromHeapObject(str);
ScriptOrigin origin(file_name);
return Compile(context, source, &origin).FromMaybe(Local<Script>());
}
// --- E x c e p t i o n s ---
v8::TryCatch::TryCatch(v8::Isolate* isolate)
@ -2727,6 +2917,12 @@ MaybeLocal<Value> v8::TryCatch::StackTrace(Local<Context> context) const {
}
v8::Local<Value> v8::TryCatch::StackTrace() const {
auto context = reinterpret_cast<v8::Isolate*>(isolate_)->GetCurrentContext();
RETURN_TO_LOCAL_UNCHECKED(StackTrace(context), Value);
}
v8::Local<v8::Message> v8::TryCatch::Message() const {
i::Object* message = reinterpret_cast<i::Object*>(message_obj_);
DCHECK(message->IsJSMessageObject() || message->IsTheHole(isolate_));
@ -2821,6 +3017,12 @@ Maybe<int> Message::GetLineNumber(Local<Context> context) const {
}
int Message::GetLineNumber() const {
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
return GetLineNumber(context).FromMaybe(0);
}
int Message::GetStartPosition() const {
auto self = Utils::OpenHandle(this);
return self->start_position();
@ -2894,6 +3096,12 @@ MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const {
}
Local<String> Message::GetSourceLine() const {
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
RETURN_TO_LOCAL_UNCHECKED(GetSourceLine(context), String)
}
void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
@ -2913,6 +3121,11 @@ Local<StackFrame> StackTrace::GetFrame(Isolate* v8_isolate,
return scope.Escape(Utils::StackFrameToLocal(info));
}
Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this));
return GetFrame(reinterpret_cast<Isolate*>(isolate), index);
}
int StackTrace::GetFrameCount() const {
return Utils::OpenHandle(this)->length();
}
@ -3892,6 +4105,16 @@ Maybe<bool> Value::BooleanValue(Local<Context> context) const {
}
bool Value::BooleanValue() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsSmi()) return *obj != i::Smi::kZero;
DCHECK(obj->IsHeapObject());
i::Isolate* isolate =
UnsafeIsolateFromHeapObject(i::Handle<i::HeapObject>::cast(obj));
return obj->BooleanValue(isolate);
}
Maybe<double> Value::NumberValue(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return Just(obj->Number());
@ -3905,6 +4128,14 @@ Maybe<double> Value::NumberValue(Local<Context> context) const {
}
double Value::NumberValue() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return obj->Number();
return NumberValue(UnsafeContextFromHeapObject(obj))
.FromMaybe(std::numeric_limits<double>::quiet_NaN());
}
Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) {
@ -3920,6 +4151,19 @@ Maybe<int64_t> Value::IntegerValue(Local<Context> context) const {
}
int64_t Value::IntegerValue() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) {
if (obj->IsSmi()) {
return i::Smi::ToInt(*obj);
} else {
return static_cast<int64_t>(obj->Number());
}
}
return IntegerValue(UnsafeContextFromHeapObject(obj)).FromMaybe(0);
}
Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return Just(NumberToInt32(*obj));
@ -3934,6 +4178,13 @@ Maybe<int32_t> Value::Int32Value(Local<Context> context) const {
}
int32_t Value::Int32Value() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return NumberToInt32(*obj);
return Int32Value(UnsafeContextFromHeapObject(obj)).FromMaybe(0);
}
Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return Just(NumberToUint32(*obj));
@ -3948,6 +4199,13 @@ Maybe<uint32_t> Value::Uint32Value(Local<Context> context) const {
}
uint32_t Value::Uint32Value() const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return NumberToUint32(*obj);
return Uint32Value(UnsafeContextFromHeapObject(obj)).FromMaybe(0);
}
MaybeLocal<Uint32> Value::ToArrayIndex(Local<Context> context) const {
auto self = Utils::OpenHandle(this);
if (self->IsSmi()) {
@ -3982,6 +4240,21 @@ Maybe<bool> Value::Equals(Local<Context> context, Local<Value> that) const {
}
bool Value::Equals(Local<Value> that) const {
auto self = Utils::OpenHandle(this);
auto other = Utils::OpenHandle(*that);
if (self->IsSmi() && other->IsSmi()) {
return self->Number() == other->Number();
}
if (self->IsJSObject() && other->IsJSObject()) {
return *self == *other;
}
auto heap_object = self->IsSmi() ? other : self;
auto context = UnsafeContextFromHeapObject(heap_object);
return Equals(context, that).FromMaybe(false);
}
bool Value::StrictEquals(Local<Value> that) const {
auto self = Utils::OpenHandle(this);
auto other = Utils::OpenHandle(*that);
@ -5305,6 +5578,11 @@ bool String::ContainsOnlyOneByte() const {
return helper.Check(*str);
}
int String::Utf8Length() const {
i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this));
return Utf8Length(reinterpret_cast<Isolate*>(isolate));
}
int String::Utf8Length(Isolate* isolate) const {
i::Handle<i::String> str = Utils::OpenHandle(this);
str = i::String::Flatten(reinterpret_cast<i::Isolate*>(isolate), str);
@ -5573,6 +5851,14 @@ int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
return writer.CompleteWrite(write_null, nchars_ref);
}
int String::WriteUtf8(char* buffer, int capacity, int* nchars_ref,
int options) const {
i::Handle<i::String> str = Utils::OpenHandle(this);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(str);
return WriteUtf8(reinterpret_cast<Isolate*>(isolate), buffer, capacity,
nchars_ref, options);
}
template <typename CharType>
static inline int WriteHelper(i::Isolate* isolate, const String* string,
CharType* buffer, int start, int length,
@ -5595,6 +5881,14 @@ static inline int WriteHelper(i::Isolate* isolate, const String* string,
}
int String::WriteOneByte(uint8_t* buffer,
int start,
int length,
int options) const {
i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this));
return WriteHelper(isolate, this, buffer, start, length, options);
}
int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start,
int length, int options) const {
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
@ -5602,6 +5896,14 @@ int String::WriteOneByte(Isolate* isolate, uint8_t* buffer, int start,
}
int String::Write(uint16_t* buffer,
int start,
int length,
int options) const {
i::Isolate* isolate = UnsafeIsolateFromHeapObject(Utils::OpenHandle(this));
return WriteHelper(isolate, this, buffer, start, length, options);
}
int String::Write(Isolate* isolate, uint16_t* buffer, int start, int length,
int options) const {
return WriteHelper(reinterpret_cast<i::Isolate*>(isolate), this, buffer,
@ -6559,6 +6861,12 @@ Local<String> v8::String::Concat(Isolate* v8_isolate, Local<String> left,
return Utils::ToLocal(result);
}
Local<String> v8::String::Concat(Local<String> left, Local<String> right) {
i::Handle<i::String> left_string = Utils::OpenHandle(*left);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(left_string);
return Concat(reinterpret_cast<Isolate*>(isolate), left, right);
}
MaybeLocal<String> v8::String::NewExternalTwoByte(
Isolate* isolate, v8::String::ExternalStringResource* resource) {
CHECK(resource && resource->data());
@ -6768,6 +7076,12 @@ bool v8::BooleanObject::ValueOf() const {
}
Local<v8::Value> v8::StringObject::New(Local<String> value) {
i::Handle<i::String> string = Utils::OpenHandle(*value);
i::Isolate* isolate = UnsafeIsolateFromHeapObject(string);
return New(reinterpret_cast<Isolate*>(isolate), value);
}
Local<v8::Value> v8::StringObject::New(Isolate* v8_isolate,
Local<String> value) {
i::Handle<i::String> string = Utils::OpenHandle(*value);
@ -6872,6 +7186,14 @@ MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context,
}
Local<v8::RegExp> v8::RegExp::New(Local<String> pattern, Flags flags) {
auto* isolate = reinterpret_cast<Isolate*>(
UnsafeIsolateFromHeapObject(Utils::OpenHandle(*pattern)));
auto context = isolate->GetCurrentContext();
RETURN_TO_LOCAL_UNCHECKED(New(context, pattern, flags), RegExp);
}
Local<v8::String> v8::RegExp::GetSource() const {
i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this);
return Utils::ToLocal(
@ -7162,6 +7484,12 @@ MaybeLocal<Promise::Resolver> Promise::Resolver::New(Local<Context> context) {
}
Local<Promise::Resolver> Promise::Resolver::New(Isolate* isolate) {
RETURN_TO_LOCAL_UNCHECKED(New(isolate->GetCurrentContext()),
Promise::Resolver);
}
Local<Promise> Promise::Resolver::GetPromise() {
i::Handle<i::JSReceiver> promise = Utils::OpenHandle(this);
return Local<Promise>::Cast(Utils::ToLocal(promise));
@ -7187,6 +7515,12 @@ Maybe<bool> Promise::Resolver::Resolve(Local<Context> context,
}
void Promise::Resolver::Resolve(Local<Value> value) {
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
USE(Resolve(context, value));
}
Maybe<bool> Promise::Resolver::Reject(Local<Context> context,
Local<Value> value) {
auto isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
@ -7206,6 +7540,12 @@ Maybe<bool> Promise::Resolver::Reject(Local<Context> context,
}
void Promise::Resolver::Reject(Local<Value> value) {
auto context = ContextFromNeverReadOnlySpaceObject(Utils::OpenHandle(this));
USE(Reject(context, value));
}
MaybeLocal<Promise> Promise::Catch(Local<Context> context,
Local<Function> handler) {
PREPARE_FOR_EXECUTION(context, Promise, Catch, Promise);
@ -7985,6 +8325,14 @@ v8::Local<v8::Context> Isolate::GetCurrentContext() {
}
v8::Local<v8::Context> Isolate::GetCallingContext() {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::Handle<i::Object> calling = isolate->GetCallingNativeContext();
if (calling.is_null()) return Local<Context>();
return Utils::ToLocal(i::Handle<i::Context>::cast(calling));
}
v8::Local<v8::Context> Isolate::GetEnteredContext() {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::Handle<i::Object> last =
@ -8482,6 +8830,18 @@ void Isolate::RemoveCallCompletedCallback(CallCompletedCallback callback) {
isolate->RemoveCallCompletedCallback(callback);
}
void Isolate::AddCallCompletedCallback(
DeprecatedCallCompletedCallback callback) {
AddCallCompletedCallback(reinterpret_cast<CallCompletedCallback>(callback));
}
void Isolate::RemoveCallCompletedCallback(
DeprecatedCallCompletedCallback callback) {
RemoveCallCompletedCallback(
reinterpret_cast<CallCompletedCallback>(callback));
}
void Isolate::AtomicsWaitWakeHandle::Wake() {
reinterpret_cast<i::AtomicsWaitWakeHandle*>(this)->Wake();
}
@ -8525,6 +8885,17 @@ void Isolate::EnqueueMicrotask(MicrotaskCallback callback, void* data) {
}
void Isolate::SetAutorunMicrotasks(bool autorun) {
SetMicrotasksPolicy(
autorun ? MicrotasksPolicy::kAuto : MicrotasksPolicy::kExplicit);
}
bool Isolate::WillAutorunMicrotasks() const {
return GetMicrotasksPolicy() == MicrotasksPolicy::kAuto;
}
void Isolate::SetMicrotasksPolicy(MicrotasksPolicy policy) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->handle_scope_implementer()->set_microtasks_policy(policy);
@ -8894,6 +9265,9 @@ String::Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
str->WriteUtf8(isolate, str_);
}
String::Utf8Value::Utf8Value(v8::Local<v8::Value> obj)
: String::Utf8Value::Utf8Value(Isolate::GetCurrent(), obj) {}
String::Utf8Value::~Utf8Value() {
i::DeleteArray(str_);
}
@ -8913,6 +9287,9 @@ String::Value::Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
str->Write(isolate, str_);
}
String::Value::Value(v8::Local<v8::Value> obj)
: String::Value::Value(v8::Isolate::GetCurrent(), obj) {}
String::Value::~Value() {
i::DeleteArray(str_);
}

View File

@ -2223,6 +2223,14 @@ bool Isolate::AreWasmThreadsEnabled(Handle<Context> context) {
return FLAG_experimental_wasm_threads;
}
Handle<Context> Isolate::GetCallingNativeContext() {
JavaScriptFrameIterator it(this);
if (it.done()) return Handle<Context>::null();
JavaScriptFrame* frame = it.frame();
Context* context = Context::cast(frame->context());
return Handle<Context>(context->native_context(), this);
}
Handle<Context> Isolate::GetIncumbentContext() {
JavaScriptFrameIterator it(this);

View File

@ -958,6 +958,10 @@ class Isolate : private HiddenFactory {
inline Handle<Context> native_context();
inline Context* raw_native_context();
// Returns the native context of the calling JavaScript code. That
// is, the native context of the top-most JavaScript frame.
Handle<Context> GetCallingNativeContext();
Handle<Context> GetIncumbentContext();
void RegisterTryCatchHandler(v8::TryCatch* that);
@ -1873,6 +1877,9 @@ class Isolate : private HiddenFactory {
friend class v8::Locker;
friend class v8::SnapshotCreator;
friend class v8::Unlocker;
friend v8::StartupData v8::V8::CreateSnapshotDataBlob(const char*);
friend v8::StartupData v8::V8::WarmUpSnapshotDataBlob(v8::StartupData,
const char*);
DISALLOW_COPY_AND_ASSIGN(Isolate);
};