Skip to content

Commit

Permalink
deps: patch the V8 API to be forward compatible with 6.7
Browse files Browse the repository at this point in the history
PR-URL: #19999
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yang Guo <yangguo@chromium.org>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
psmarshall authored and jasnell committed Apr 19, 2018
1 parent efda6fb commit 2a3f8c3
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 109 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.4',
'v8_embedder_string': '-node.5',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
4 changes: 2 additions & 2 deletions deps/v8/include/libplatform/libplatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ V8_PLATFORM_EXPORT std::unique_ptr<v8::Platform> NewDefaultPlatform(
int thread_pool_size = 0,
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
InProcessStackDumping in_process_stack_dumping =
InProcessStackDumping::kEnabled,
InProcessStackDumping::kDisabled,
std::unique_ptr<v8::TracingController> tracing_controller = {});

V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
Expand All @@ -47,7 +47,7 @@ V8_PLATFORM_EXPORT V8_DEPRECATE_SOON(
int thread_pool_size = 0,
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled,
InProcessStackDumping in_process_stack_dumping =
InProcessStackDumping::kEnabled,
InProcessStackDumping::kDisabled,
v8::TracingController* tracing_controller = nullptr));

/**
Expand Down
63 changes: 56 additions & 7 deletions deps/v8/include/v8-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#ifndef V8_V8_PLATFORM_H_
#define V8_V8_PLATFORM_H_

#include <cstdlib>
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string>

#include "v8config.h" // NOLINT(build/include)

namespace v8 {

class Isolate;
Expand Down Expand Up @@ -285,14 +288,23 @@ class Platform {
*/
virtual bool OnCriticalMemoryPressure(size_t length) { return false; }

virtual int NumberOfWorkerThreads() {
return static_cast<int>(NumberOfAvailableBackgroundThreads());
}

/**
* Gets the number of threads that are used to execute background tasks. Is
* used to estimate the number of tasks a work package should be split into.
* A return value of 0 means that there are no background threads available.
* Note that a value of 0 won't prohibit V8 from posting tasks using
* |CallOnBackgroundThread|.
*/
virtual size_t NumberOfAvailableBackgroundThreads() { return 0; }
V8_DEPRECATE_SOON(
"NumberOfAvailableBackgroundThreads() is deprecated, use "
"NumberOfAvailableBackgroundThreads() instead.",
virtual size_t NumberOfAvailableBackgroundThreads()) {
return 0;
}

/**
* Returns a TaskRunner which can be used to post a task on the foreground.
Expand All @@ -309,11 +321,28 @@ class Platform {
* Returns a TaskRunner which can be used to post a task on a background.
* This function should only be called from a foreground thread.
*/
virtual std::shared_ptr<v8::TaskRunner> GetBackgroundTaskRunner(
V8_DEPRECATE_SOON(
"GetBackgroundTaskRunner() is deprecated, use "
"GetWorkerThreadsTaskRunner() "
"instead.",
virtual std::shared_ptr<v8::TaskRunner> GetBackgroundTaskRunner(
Isolate* isolate)) {
// TODO(gab): Remove this method when all embedders have moved to
// GetWorkerThreadsTaskRunner().

// An implementation needs to be provided here because this is called by the
// default GetWorkerThreadsTaskRunner() implementation below. In practice
// however, all code either:
// - Overrides GetWorkerThreadsTaskRunner() (thus not making this call) --
// i.e. all v8 code.
// - Overrides this method (thus not making this call) -- i.e. all
// unadapted embedders.
abort();
}

virtual std::shared_ptr<v8::TaskRunner> GetWorkerThreadsTaskRunner(
Isolate* isolate) {
// TODO(ahaas): Make this function abstract after it got implemented on all
// platforms.
return {};
return GetBackgroundTaskRunner(isolate);
}

/**
Expand All @@ -323,8 +352,28 @@ class Platform {
* of tasks wrt order of scheduling, nor is there a guarantee about the
* thread the task will be run on.
*/
virtual void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime) = 0;
V8_DEPRECATE_SOON(
"ExpectedRuntime is deprecated, use CallOnWorkerThread() instead.",
virtual void CallOnBackgroundThread(Task* task,
ExpectedRuntime expected_runtime)) {
// An implementation needs to be provided here because this is called by the
// default implementation below. In practice however, all code either:
// - Overrides the new method (thus not making this call) -- i.e. all v8
// code.
// - Overrides this method (thus not making this call) -- i.e. all
// unadapted embedders.
abort();
}

virtual void CallOnWorkerThread(std::unique_ptr<Task> task) {
CallOnBackgroundThread(task.release(), kShortRunningTask);
}

virtual void CallBlockingTaskOnWorkerThread(std::unique_ptr<Task> task) {
// Embedders may optionally override this to process these tasks in a high
// priority pool.
CallOnWorkerThread(std::move(task));
}

/**
* Schedules a task to be invoked on a foreground thread wrt a specific
Expand Down
79 changes: 32 additions & 47 deletions deps/v8/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,9 @@ class V8_EXPORT ScriptCompiler {
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,
Local<Object> context_extensions[]);
Local<Object> context_extensions[],
CompileOptions options = kNoCompileOptions,
NoCacheReason no_cache_reason = kNoCacheNoReason);

/**
* Creates and returns code cache for the specified unbound_script.
Expand Down Expand Up @@ -1641,7 +1643,7 @@ class V8_EXPORT Message {
* Returns the index within the line of the first character where
* the error occurred.
*/
V8_DEPRECATED("Use maybe version", int GetStartColumn() const);
int GetStartColumn() const;
V8_WARN_UNUSED_RESULT Maybe<int> GetStartColumn(Local<Context> context) const;

/**
Expand Down Expand Up @@ -3075,6 +3077,8 @@ enum PropertyFilter {
SKIP_SYMBOLS = 16
};

enum class SideEffectType { kHasSideEffect, kHasNoSideEffect };

/**
* Keys/Properties filter enums:
*
Expand Down Expand Up @@ -3207,13 +3211,12 @@ class V8_EXPORT Object : public Value {
V8_WARN_UNUSED_RESULT Maybe<bool> Delete(Local<Context> context,
uint32_t index);

V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(Local<Context> context,
Local<Name> name,
AccessorNameGetterCallback getter,
AccessorNameSetterCallback setter = 0,
MaybeLocal<Value> data = MaybeLocal<Value>(),
AccessControl settings = DEFAULT,
PropertyAttribute attribute = None);
V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
Local<Context> context, Local<Name> name,
AccessorNameGetterCallback getter, AccessorNameSetterCallback setter = 0,
MaybeLocal<Value> data = MaybeLocal<Value>(),
AccessControl settings = DEFAULT, PropertyAttribute attribute = None,
SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);

void SetAccessorProperty(Local<Name> name, Local<Function> getter,
Local<Function> setter = Local<Function>(),
Expand All @@ -3228,7 +3231,8 @@ class V8_EXPORT Object : public Value {
Local<Context> context, Local<Name> name,
AccessorNameGetterCallback getter,
AccessorNameSetterCallback setter = nullptr,
Local<Value> data = Local<Value>(), PropertyAttribute attributes = None);
Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);

/**
* Attempts to create a property with the given name which behaves like a data
Expand All @@ -3241,7 +3245,8 @@ class V8_EXPORT Object : public Value {
V8_WARN_UNUSED_RESULT Maybe<bool> SetLazyDataProperty(
Local<Context> context, Local<Name> name,
AccessorNameGetterCallback getter, Local<Value> data = Local<Value>(),
PropertyAttribute attributes = None);
PropertyAttribute attributes = None,
SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect);

/**
* Functionality for private properties.
Expand Down Expand Up @@ -3496,7 +3501,7 @@ class V8_EXPORT Object : public Value {
/**
* Return the isolate to which the Object belongs to.
*/
V8_DEPRECATE_SOON("Keep track of isolate correctly", Isolate* GetIsolate());
Isolate* GetIsolate();

static Local<Object> New(Isolate* isolate);

Expand Down Expand Up @@ -3833,7 +3838,8 @@ class V8_EXPORT Function : public Object {
static MaybeLocal<Function> New(
Local<Context> context, FunctionCallback callback,
Local<Value> data = Local<Value>(), int length = 0,
ConstructorBehavior behavior = ConstructorBehavior::kAllow);
ConstructorBehavior behavior = ConstructorBehavior::kAllow,
SideEffectType side_effect_type = SideEffectType::kHasSideEffect);
static V8_DEPRECATE_SOON(
"Use maybe version",
Local<Function> New(Isolate* isolate, FunctionCallback callback,
Expand Down Expand Up @@ -4271,13 +4277,6 @@ class V8_EXPORT ArrayBuffer : public Object {
*/
virtual void* AllocateUninitialized(size_t length) = 0;

/**
* Reserved |length| bytes, but do not commit the memory. Must call
* |SetProtection| to make memory accessible.
*/
// TODO(eholk): make this pure virtual once blink implements this.
virtual void* Reserve(size_t length);

/**
* Free the memory block of size |length|, pointed to by |data|.
* That memory is guaranteed to be previously allocated by |Allocate|.
Expand All @@ -4286,27 +4285,6 @@ class V8_EXPORT ArrayBuffer : public Object {

enum class AllocationMode { kNormal, kReservation };

/**
* Free the memory block of size |length|, pointed to by |data|.
* That memory is guaranteed to be previously allocated by |Allocate| or
* |Reserve|, depending on |mode|.
*/
// TODO(eholk): make this pure virtual once blink implements this.
virtual void Free(void* data, size_t length, AllocationMode mode);

enum class Protection { kNoAccess, kReadWrite };

/**
* Change the protection on a region of memory.
*
* On platforms that make a distinction between reserving and committing
* memory, changing the protection to kReadWrite must also ensure the memory
* is committed.
*/
// TODO(eholk): make this pure virtual once blink implements this.
virtual void SetProtection(void* data, size_t length,
Protection protection);

/**
* malloc/free based convenience allocator.
*
Expand Down Expand Up @@ -5496,7 +5474,8 @@ class V8_EXPORT FunctionTemplate : public Template {
Isolate* isolate, FunctionCallback callback = 0,
Local<Value> data = Local<Value>(),
Local<Signature> signature = Local<Signature>(), int length = 0,
ConstructorBehavior behavior = ConstructorBehavior::kAllow);
ConstructorBehavior behavior = ConstructorBehavior::kAllow,
SideEffectType side_effect_type = SideEffectType::kHasSideEffect);

/** Get a template included in the snapshot by index. */
static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
Expand All @@ -5508,7 +5487,8 @@ class V8_EXPORT FunctionTemplate : public Template {
static Local<FunctionTemplate> NewWithCache(
Isolate* isolate, FunctionCallback callback,
Local<Private> cache_property, Local<Value> data = Local<Value>(),
Local<Signature> signature = Local<Signature>(), int length = 0);
Local<Signature> signature = Local<Signature>(), int length = 0,
SideEffectType side_effect_type = SideEffectType::kHasSideEffect);

/** Returns the unique function instance in the current execution context.*/
V8_DEPRECATE_SOON("Use maybe version", Local<Function> GetFunction());
Expand All @@ -5529,8 +5509,9 @@ class V8_EXPORT FunctionTemplate : public Template {
* callback is called whenever the function created from this
* FunctionTemplate is called.
*/
void SetCallHandler(FunctionCallback callback,
Local<Value> data = Local<Value>());
void SetCallHandler(
FunctionCallback callback, Local<Value> data = Local<Value>(),
SideEffectType side_effect_type = SideEffectType::kHasSideEffect);

/** Set the predefined length property for the FunctionTemplate. */
void SetLength(int length);
Expand Down Expand Up @@ -5828,7 +5809,7 @@ class V8_EXPORT ObjectTemplate : public Template {
* \param data A piece of data that will be passed to the callbacks
* whenever they are invoked.
*/
V8_DEPRECATE_SOON(
V8_DEPRECATED(
"Use SetHandler(const NamedPropertyHandlerConfiguration) "
"with the kOnlyInterceptStrings flag set.",
void SetNamedPropertyHandler(
Expand Down Expand Up @@ -6586,8 +6567,11 @@ struct JitCodeEvent {
// statement, and is used to indicate possible break locations.
enum PositionType { POSITION, STATEMENT_POSITION };

enum CodeType { BYTE_CODE, JIT_CODE };

// Type of event.
EventType type;
CodeType code_type;
// Start of the instructions.
void* code_start;
// Size of the instructions.
Expand Down Expand Up @@ -8025,7 +8009,8 @@ class V8_EXPORT V8 {
* Enable the default signal handler rather than using one provided by the
* embedder.
*/
static bool RegisterDefaultSignalHandler();
V8_DEPRECATE_SOON("Use EnableWebAssemblyTrapHandler",
static bool RegisterDefaultSignalHandler());

private:
V8();
Expand Down
Loading

0 comments on commit 2a3f8c3

Please sign in to comment.