Commit eaba98d9 authored by yangguo's avatar yangguo Committed by Commit bot

Unify symbols sharing across native scripts and runtime.

We currently have several ways to share symbols that are used in
both native scripts and the runtime. This change unifies this.
We do not use the symbols registry since we don't need the
registry any longer after bootstrapping, but the registry stays
alive afterwards.

R=mlippautz@chromium.org, rossberg@chromium.org

Review URL: https://codereview.chromium.org/1293493004

Cr-Commit-Position: refs/heads/master@{#30280}
parent 2e84d142
...@@ -10,6 +10,15 @@ var $arrayValues; ...@@ -10,6 +10,15 @@ var $arrayValues;
%CheckIsBootstrapping(); %CheckIsBootstrapping();
// -----------------------------------------------------------------------
// Imports
var arrayIterationKindSymbol =
utils.GetPrivateSymbol("array_iteration_kind_symbol");
var arrayIteratorNextIndexSymbol =
utils.GetPrivateSymbol("array_iterator_next_symbol");
var arrayIteratorObjectSymbol =
utils.GetPrivateSymbol("array_iterator_object_symbol");
var GlobalArray = global.Array; var GlobalArray = global.Array;
macro TYPED_ARRAYS(FUNCTION) macro TYPED_ARRAYS(FUNCTION)
...@@ -30,10 +39,7 @@ endmacro ...@@ -30,10 +39,7 @@ endmacro
TYPED_ARRAYS(COPY_FROM_GLOBAL) TYPED_ARRAYS(COPY_FROM_GLOBAL)
var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); // -----------------------------------------------------------------------
var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next");
var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind");
function ArrayIterator() {} function ArrayIterator() {}
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "src/extensions/gc-extension.h" #include "src/extensions/gc-extension.h"
#include "src/extensions/statistics-extension.h" #include "src/extensions/statistics-extension.h"
#include "src/extensions/trigger-failure-extension.h" #include "src/extensions/trigger-failure-extension.h"
#include "src/heap/heap.h"
#include "src/snapshot/natives.h" #include "src/snapshot/natives.h"
#include "src/snapshot/snapshot.h" #include "src/snapshot/snapshot.h"
#include "third_party/fdlibm/fdlibm.h" #include "third_party/fdlibm/fdlibm.h"
...@@ -1795,8 +1796,6 @@ void Bootstrapper::ImportNatives(Isolate* isolate, Handle<JSObject> container) { ...@@ -1795,8 +1796,6 @@ void Bootstrapper::ImportNatives(Isolate* isolate, Handle<JSObject> container) {
INSTALL_NATIVE(JSFunction, "URIError", uri_error_function); INSTALL_NATIVE(JSFunction, "URIError", uri_error_function);
INSTALL_NATIVE(JSFunction, "MakeError", make_error_function); INSTALL_NATIVE(JSFunction, "MakeError", make_error_function);
INSTALL_NATIVE(Symbol, "promiseStatus", promise_status);
INSTALL_NATIVE(Symbol, "promiseValue", promise_value);
INSTALL_NATIVE(JSFunction, "PromiseCreate", promise_create); INSTALL_NATIVE(JSFunction, "PromiseCreate", promise_create);
INSTALL_NATIVE(JSFunction, "PromiseResolve", promise_resolve); INSTALL_NATIVE(JSFunction, "PromiseResolve", promise_resolve);
INSTALL_NATIVE(JSFunction, "PromiseReject", promise_reject); INSTALL_NATIVE(JSFunction, "PromiseReject", promise_reject);
...@@ -1907,6 +1906,21 @@ bool Bootstrapper::InstallJSBuiltins(Isolate* isolate, ...@@ -1907,6 +1906,21 @@ bool Bootstrapper::InstallJSBuiltins(Isolate* isolate,
} }
void Bootstrapper::ExportPrivateSymbols(Isolate* isolate,
Handle<JSObject> container) {
HandleScope scope(isolate);
#define EXPORT_PRIVATE_SYMBOL(NAME) \
Handle<String> NAME##_name = \
isolate->factory()->NewStringFromAsciiChecked(#NAME); \
JSObject::AddProperty(container, NAME##_name, isolate->factory()->NAME(), \
NONE);
PRIVATE_SYMBOL_LIST(EXPORT_PRIVATE_SYMBOL)
#undef EXPORT_PRIVATE_SYMBOL
}
#define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \ #define EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(id) \
void Genesis::InitializeGlobal_##id() {} void Genesis::InitializeGlobal_##id() {}
...@@ -2789,24 +2803,6 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) { ...@@ -2789,24 +2803,6 @@ bool Genesis::InstallSpecialObjects(Handle<Context> native_context) {
JSObject::AddProperty(global, natives_key, natives, DONT_ENUM); JSObject::AddProperty(global, natives_key, natives, DONT_ENUM);
} }
// Expose the stack trace symbol to native JS.
RETURN_ON_EXCEPTION_VALUE(isolate,
JSObject::SetOwnPropertyIgnoreAttributes(
handle(native_context->builtins(), isolate),
factory->InternalizeOneByteString(
STATIC_CHAR_VECTOR("$stackTraceSymbol")),
factory->stack_trace_symbol(), NONE),
false);
// Expose the internal error symbol to native JS
RETURN_ON_EXCEPTION_VALUE(isolate,
JSObject::SetOwnPropertyIgnoreAttributes(
handle(native_context->builtins(), isolate),
factory->InternalizeOneByteString(
STATIC_CHAR_VECTOR("$internalErrorSymbol")),
factory->internal_error_symbol(), NONE),
false);
// Expose the debug global object in global if a name for it is specified. // Expose the debug global object in global if a name for it is specified.
if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) {
// If loading fails we just bail out without installing the // If loading fails we just bail out without installing the
......
...@@ -123,6 +123,8 @@ class Bootstrapper final { ...@@ -123,6 +123,8 @@ class Bootstrapper final {
static void ImportExperimentalNatives(Isolate* isolate, static void ImportExperimentalNatives(Isolate* isolate,
Handle<JSObject> container); Handle<JSObject> container);
static bool InstallJSBuiltins(Isolate* isolate, Handle<JSObject> container); static bool InstallJSBuiltins(Isolate* isolate, Handle<JSObject> container);
static void ExportPrivateSymbols(Isolate* isolate,
Handle<JSObject> container);
private: private:
Isolate* isolate_; Isolate* isolate_;
......
...@@ -16,6 +16,7 @@ var $getExistingHash; ...@@ -16,6 +16,7 @@ var $getExistingHash;
var GlobalMap = global.Map; var GlobalMap = global.Map;
var GlobalObject = global.Object; var GlobalObject = global.Object;
var GlobalSet = global.Set; var GlobalSet = global.Set;
var hashCodeSymbol = utils.GetPrivateSymbol("hash_code_symbol");
var IntRandom; var IntRandom;
utils.Import(function(from) { utils.Import(function(from) {
...@@ -90,8 +91,6 @@ function ComputeIntegerHash(key, seed) { ...@@ -90,8 +91,6 @@ function ComputeIntegerHash(key, seed) {
} }
%SetForceInlineFlag(ComputeIntegerHash); %SetForceInlineFlag(ComputeIntegerHash);
var hashCodeSymbol = GLOBAL_PRIVATE("hash_code_symbol");
function GetExistingHash(key) { function GetExistingHash(key) {
if (%_IsSmi(key)) { if (%_IsSmi(key)) {
return ComputeIntegerHash(key, 0); return ComputeIntegerHash(key, 0);
......
...@@ -160,8 +160,6 @@ enum BindingFlags { ...@@ -160,8 +160,6 @@ enum BindingFlags {
V(TYPE_ERROR_FUNCTION_INDEX, JSFunction, type_error_function) \ V(TYPE_ERROR_FUNCTION_INDEX, JSFunction, type_error_function) \
V(URI_ERROR_FUNCTION_INDEX, JSFunction, uri_error_function) \ V(URI_ERROR_FUNCTION_INDEX, JSFunction, uri_error_function) \
V(MAKE_ERROR_FUNCTION_INDEX, JSFunction, make_error_function) \ V(MAKE_ERROR_FUNCTION_INDEX, JSFunction, make_error_function) \
V(PROMISE_STATUS_INDEX, Symbol, promise_status) \
V(PROMISE_VALUE_INDEX, Symbol, promise_value) \
V(PROMISE_CREATE_INDEX, JSFunction, promise_create) \ V(PROMISE_CREATE_INDEX, JSFunction, promise_create) \
V(PROMISE_RESOLVE_INDEX, JSFunction, promise_resolve) \ V(PROMISE_RESOLVE_INDEX, JSFunction, promise_resolve) \
V(PROMISE_REJECT_INDEX, JSFunction, promise_reject) \ V(PROMISE_REJECT_INDEX, JSFunction, promise_reject) \
......
...@@ -13,6 +13,8 @@ var GlobalArray = global.Array; ...@@ -13,6 +13,8 @@ var GlobalArray = global.Array;
var IsNaN = global.isNaN; var IsNaN = global.isNaN;
var JSONStringify = global.JSON.stringify; var JSONStringify = global.JSON.stringify;
var MathMin = global.Math.min; var MathMin = global.Math.min;
var promiseStatusSymbol = utils.GetPrivateSymbol("promise_status_symbol");
var promiseValueSymbol = utils.GetPrivateSymbol("promise_value_symbol");
var ToBoolean; var ToBoolean;
var ToString; var ToString;
...@@ -109,7 +111,7 @@ function ClearMirrorCache(value) { ...@@ -109,7 +111,7 @@ function ClearMirrorCache(value) {
function ObjectIsPromise(value) { function ObjectIsPromise(value) {
try { try {
return IS_SPEC_OBJECT(value) && return IS_SPEC_OBJECT(value) &&
!IS_UNDEFINED(%DebugGetProperty(value, builtins.$promiseStatus)); !IS_UNDEFINED(%DebugGetProperty(value, promiseStatusSymbol));
} catch (e) { } catch (e) {
return false; return false;
} }
...@@ -1326,7 +1328,7 @@ inherits(PromiseMirror, ObjectMirror); ...@@ -1326,7 +1328,7 @@ inherits(PromiseMirror, ObjectMirror);
function PromiseGetStatus_(value) { function PromiseGetStatus_(value) {
var status = %DebugGetProperty(value, builtins.$promiseStatus); var status = %DebugGetProperty(value, promiseStatusSymbol);
if (status == 0) return "pending"; if (status == 0) return "pending";
if (status == 1) return "resolved"; if (status == 1) return "resolved";
return "rejected"; return "rejected";
...@@ -1334,7 +1336,7 @@ function PromiseGetStatus_(value) { ...@@ -1334,7 +1336,7 @@ function PromiseGetStatus_(value) {
function PromiseGetValue_(value) { function PromiseGetValue_(value) {
return %DebugGetProperty(value, builtins.$promiseValue); return %DebugGetProperty(value, promiseValueSymbol);
} }
......
...@@ -3392,19 +3392,6 @@ void Heap::CreateInitialObjects() { ...@@ -3392,19 +3392,6 @@ void Heap::CreateInitialObjects() {
} }
void Heap::AddPrivateGlobalSymbols(Handle<Object> private_intern_table) {
#define ADD_SYMBOL_TO_PRIVATE_INTERN_TABLE(name_arg) \
{ \
Handle<Symbol> symbol(Symbol::cast(roots_[k##name_arg##RootIndex])); \
Handle<String> name_arg##d(String::cast(symbol->name())); \
JSObject::AddProperty(Handle<JSObject>::cast(private_intern_table), \
name_arg##d, symbol, NONE); \
}
PRIVATE_SYMBOL_LIST(ADD_SYMBOL_TO_PRIVATE_INTERN_TABLE)
#undef ADD_SYMBOL_TO_PRIVATE_INTERN_TABLE
}
bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) { bool Heap::RootCanBeWrittenAfterInitialization(Heap::RootListIndex root_index) {
switch (root_index) { switch (root_index) {
case kStoreBufferTopRootIndex: case kStoreBufferTopRootIndex:
......
...@@ -266,9 +266,6 @@ namespace internal { ...@@ -266,9 +266,6 @@ namespace internal {
V(WeakSet_string, "WeakSet") \ V(WeakSet_string, "WeakSet") \
V(for_string, "for") \ V(for_string, "for") \
V(for_api_string, "for_api") \ V(for_api_string, "for_api") \
V(for_intern_string, "for_intern") \
V(private_api_string, "private_api") \
V(private_intern_string, "private_intern") \
V(Date_string, "Date") \ V(Date_string, "Date") \
V(char_at_string, "CharAt") \ V(char_at_string, "CharAt") \
V(undefined_string, "undefined") \ V(undefined_string, "undefined") \
...@@ -299,31 +296,47 @@ namespace internal { ...@@ -299,31 +296,47 @@ namespace internal {
V(Error_string, "Error") \ V(Error_string, "Error") \
V(RegExp_string, "RegExp") V(RegExp_string, "RegExp")
#define PRIVATE_SYMBOL_LIST(V) \ #define PRIVATE_SYMBOL_LIST(V) \
V(nonextensible_symbol) \ V(array_iteration_kind_symbol) \
V(sealed_symbol) \ V(array_iterator_next_symbol) \
V(hash_code_symbol) \ V(array_iterator_object_symbol) \
V(frozen_symbol) \ V(call_site_function_symbol) \
V(nonexistent_symbol) \ V(call_site_position_symbol) \
V(elements_transition_symbol) \ V(call_site_receiver_symbol) \
V(observed_symbol) \ V(call_site_strict_symbol) \
V(uninitialized_symbol) \ V(class_end_position_symbol) \
V(megamorphic_symbol) \ V(class_start_position_symbol) \
V(premonomorphic_symbol) \ V(detailed_stack_trace_symbol) \
V(stack_trace_symbol) \ V(elements_transition_symbol) \
V(detailed_stack_trace_symbol) \ V(error_end_pos_symbol) \
V(normal_ic_symbol) \ V(error_script_symbol) \
V(home_object_symbol) \ V(error_start_pos_symbol) \
V(intl_initialized_marker_symbol) \ V(formatted_stack_trace_symbol) \
V(intl_impl_object_symbol) \ V(frozen_symbol) \
V(promise_debug_marker_symbol) \ V(hash_code_symbol) \
V(promise_has_handler_symbol) \ V(home_object_symbol) \
V(class_start_position_symbol) \ V(internal_error_symbol) \
V(class_end_position_symbol) \ V(intl_impl_object_symbol) \
V(error_start_pos_symbol) \ V(intl_initialized_marker_symbol) \
V(error_end_pos_symbol) \ V(megamorphic_symbol) \
V(error_script_symbol) \ V(nonexistent_symbol) \
V(internal_error_symbol) V(nonextensible_symbol) \
V(normal_ic_symbol) \
V(observed_symbol) \
V(premonomorphic_symbol) \
V(promise_debug_marker_symbol) \
V(promise_has_handler_symbol) \
V(promise_on_resolve_symbol) \
V(promise_on_reject_symbol) \
V(promise_raw_symbol) \
V(promise_status_symbol) \
V(promise_value_symbol) \
V(sealed_symbol) \
V(stack_trace_symbol) \
V(string_iterator_iterated_string_symbol) \
V(string_iterator_next_index_symbol) \
V(uninitialized_symbol)
#define PUBLIC_SYMBOL_LIST(V) \ #define PUBLIC_SYMBOL_LIST(V) \
V(has_instance_symbol, symbolHasInstance, Symbol.hasInstance) \ V(has_instance_symbol, symbolHasInstance, Symbol.hasInstance) \
...@@ -1805,8 +1818,6 @@ class Heap { ...@@ -1805,8 +1818,6 @@ class Heap {
static const ConstantStringTable constant_string_table[]; static const ConstantStringTable constant_string_table[];
static const StructTable struct_table[]; static const StructTable struct_table[];
void AddPrivateGlobalSymbols(Handle<Object> private_intern_table);
struct GCCallbackPair { struct GCCallbackPair {
GCCallbackPair(v8::Isolate::GCCallback callback, GCType gc_type, GCCallbackPair(v8::Isolate::GCCallback callback, GCType gc_type,
bool pass_isolate) bool pass_isolate)
......
...@@ -2561,9 +2561,6 @@ Handle<JSObject> Isolate::GetSymbolRegistry() { ...@@ -2561,9 +2561,6 @@ Handle<JSObject> Isolate::GetSymbolRegistry() {
SetUpSubregistry(registry, map, "for"); SetUpSubregistry(registry, map, "for");
SetUpSubregistry(registry, map, "for_api"); SetUpSubregistry(registry, map, "for_api");
SetUpSubregistry(registry, map, "keyFor"); SetUpSubregistry(registry, map, "keyFor");
SetUpSubregistry(registry, map, "private_api");
heap()->AddPrivateGlobalSymbols(
SetUpSubregistry(registry, map, "private_intern"));
} }
return Handle<JSObject>::cast(factory()->symbol_registry()); return Handle<JSObject>::cast(factory()->symbol_registry());
} }
......
...@@ -159,14 +159,11 @@ macro SHOULD_CREATE_WRAPPER(functionName, receiver) = (!IS_SPEC_OBJECT(receiver) ...@@ -159,14 +159,11 @@ macro SHOULD_CREATE_WRAPPER(functionName, receiver) = (!IS_SPEC_OBJECT(receiver)
macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array)); macro HAS_INDEX(array, index, is_array) = ((is_array && %_HasFastPackedElements(%IS_VAR(array))) ? (index < array.length) : (index in array));
# Private names. # Private names.
macro GLOBAL_PRIVATE(name) = (%CreateGlobalPrivateSymbol(name));
macro NEW_PRIVATE(name) = (%CreatePrivateSymbol(name));
macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym)); macro IS_PRIVATE(sym) = (%SymbolIsPrivate(sym));
macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym)); macro HAS_PRIVATE(obj, sym) = (%HasOwnProperty(obj, sym));
macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym])); macro HAS_DEFINED_PRIVATE(obj, sym) = (!IS_UNDEFINED(obj[sym]));
macro GET_PRIVATE(obj, sym) = (obj[sym]); macro GET_PRIVATE(obj, sym) = (obj[sym]);
macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val); macro SET_PRIVATE(obj, sym, val) = (obj[sym] = val);
macro DELETE_PRIVATE(obj, sym) = (delete obj[sym]);
# Constants. The compiler constant folds them. # Constants. The compiler constant folds them.
define NAN = $NaN; define NAN = $NaN;
......
...@@ -138,37 +138,50 @@ base::SmartArrayPointer<char> MessageHandler::GetLocalizedMessage( ...@@ -138,37 +138,50 @@ base::SmartArrayPointer<char> MessageHandler::GetLocalizedMessage(
} }
Handle<Object> CallSite::GetFileName(Isolate* isolate) { CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj)
Handle<Object> script(fun_->shared()->script(), isolate); : isolate_(isolate) {
receiver_ = JSObject::GetDataProperty(
call_site_obj, isolate->factory()->call_site_receiver_symbol());
fun_ = Handle<JSFunction>::cast(JSObject::GetDataProperty(
call_site_obj, isolate->factory()->call_site_function_symbol()));
pos_ = Handle<Smi>::cast(JSObject::GetDataProperty(
call_site_obj,
isolate->factory()->call_site_position_symbol()))
->value();
}
Handle<Object> CallSite::GetFileName() {
Handle<Object> script(fun_->shared()->script(), isolate_);
if (script->IsScript()) { if (script->IsScript()) {
return Handle<Object>(Handle<Script>::cast(script)->name(), isolate); return Handle<Object>(Handle<Script>::cast(script)->name(), isolate_);
} }
return isolate->factory()->null_value(); return isolate_->factory()->null_value();
} }
Handle<Object> CallSite::GetFunctionName(Isolate* isolate) { Handle<Object> CallSite::GetFunctionName() {
Handle<String> result = JSFunction::GetDebugName(fun_); Handle<String> result = JSFunction::GetDebugName(fun_);
if (result->length() != 0) return result; if (result->length() != 0) return result;
Handle<Object> script(fun_->shared()->script(), isolate); Handle<Object> script(fun_->shared()->script(), isolate_);
if (script->IsScript() && if (script->IsScript() &&
Handle<Script>::cast(script)->compilation_type() == Handle<Script>::cast(script)->compilation_type() ==
Script::COMPILATION_TYPE_EVAL) { Script::COMPILATION_TYPE_EVAL) {
return isolate->factory()->eval_string(); return isolate_->factory()->eval_string();
} }
return isolate->factory()->null_value(); return isolate_->factory()->null_value();
} }
Handle<Object> CallSite::GetScriptNameOrSourceUrl(Isolate* isolate) { Handle<Object> CallSite::GetScriptNameOrSourceUrl() {
Handle<Object> script_obj(fun_->shared()->script(), isolate); Handle<Object> script_obj(fun_->shared()->script(), isolate_);
if (script_obj->IsScript()) { if (script_obj->IsScript()) {
Handle<Script> script = Handle<Script>::cast(script_obj); Handle<Script> script = Handle<Script>::cast(script_obj);
Object* source_url = script->source_url(); Object* source_url = script->source_url();
if (source_url->IsString()) return Handle<Object>(source_url, isolate); if (source_url->IsString()) return Handle<Object>(source_url, isolate_);
return Handle<Object>(script->name(), isolate); return Handle<Object>(script->name(), isolate_);
} }
return isolate->factory()->null_value(); return isolate_->factory()->null_value();
} }
...@@ -190,25 +203,25 @@ bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name, ...@@ -190,25 +203,25 @@ bool CheckMethodName(Isolate* isolate, Handle<JSObject> obj, Handle<Name> name,
} }
Handle<Object> CallSite::GetMethodName(Isolate* isolate) { Handle<Object> CallSite::GetMethodName() {
MaybeHandle<JSReceiver> maybe = Object::ToObject(isolate, receiver_); MaybeHandle<JSReceiver> maybe = Object::ToObject(isolate_, receiver_);
Handle<JSReceiver> receiver; Handle<JSReceiver> receiver;
if (!maybe.ToHandle(&receiver) || !receiver->IsJSObject()) { if (!maybe.ToHandle(&receiver) || !receiver->IsJSObject()) {
return isolate->factory()->null_value(); return isolate_->factory()->null_value();
} }
Handle<JSObject> obj = Handle<JSObject>::cast(receiver); Handle<JSObject> obj = Handle<JSObject>::cast(receiver);
Handle<Object> function_name(fun_->shared()->name(), isolate); Handle<Object> function_name(fun_->shared()->name(), isolate_);
if (function_name->IsName()) { if (function_name->IsName()) {
Handle<Name> name = Handle<Name>::cast(function_name); Handle<Name> name = Handle<Name>::cast(function_name);
if (CheckMethodName(isolate, obj, name, fun_, if (CheckMethodName(isolate_, obj, name, fun_,
LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR)) LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR))
return name; return name;
} }
HandleScope outer_scope(isolate); HandleScope outer_scope(isolate_);
Handle<Object> result; Handle<Object> result;
for (PrototypeIterator iter(isolate, obj, for (PrototypeIterator iter(isolate_, obj,
PrototypeIterator::START_AT_RECEIVER); PrototypeIterator::START_AT_RECEIVER);
!iter.IsAtEnd(); iter.Advance()) { !iter.IsAtEnd(); iter.Advance()) {
Handle<Object> current = PrototypeIterator::GetCurrent(iter); Handle<Object> current = PrototypeIterator::GetCurrent(iter);
...@@ -217,26 +230,26 @@ Handle<Object> CallSite::GetMethodName(Isolate* isolate) { ...@@ -217,26 +230,26 @@ Handle<Object> CallSite::GetMethodName(Isolate* isolate) {
if (current_obj->IsAccessCheckNeeded()) break; if (current_obj->IsAccessCheckNeeded()) break;
Handle<FixedArray> keys = JSObject::GetEnumPropertyKeys(current_obj, false); Handle<FixedArray> keys = JSObject::GetEnumPropertyKeys(current_obj, false);
for (int i = 0; i < keys->length(); i++) { for (int i = 0; i < keys->length(); i++) {
HandleScope inner_scope(isolate); HandleScope inner_scope(isolate_);
if (!keys->get(i)->IsName()) continue; if (!keys->get(i)->IsName()) continue;
Handle<Name> name_key(Name::cast(keys->get(i)), isolate); Handle<Name> name_key(Name::cast(keys->get(i)), isolate_);
if (!CheckMethodName(isolate, current_obj, name_key, fun_, if (!CheckMethodName(isolate_, current_obj, name_key, fun_,
LookupIterator::OWN_SKIP_INTERCEPTOR)) LookupIterator::OWN_SKIP_INTERCEPTOR))
continue; continue;
// Return null in case of duplicates to avoid confusion. // Return null in case of duplicates to avoid confusion.
if (!result.is_null()) return isolate->factory()->null_value(); if (!result.is_null()) return isolate_->factory()->null_value();
result = inner_scope.CloseAndEscape(name_key); result = inner_scope.CloseAndEscape(name_key);
} }
} }
if (!result.is_null()) return outer_scope.CloseAndEscape(result); if (!result.is_null()) return outer_scope.CloseAndEscape(result);
return isolate->factory()->null_value(); return isolate_->factory()->null_value();
} }
int CallSite::GetLineNumber(Isolate* isolate) { int CallSite::GetLineNumber() {
if (pos_ >= 0) { if (pos_ >= 0) {
Handle<Object> script_obj(fun_->shared()->script(), isolate); Handle<Object> script_obj(fun_->shared()->script(), isolate_);
if (script_obj->IsScript()) { if (script_obj->IsScript()) {
Handle<Script> script = Handle<Script>::cast(script_obj); Handle<Script> script = Handle<Script>::cast(script_obj);
return Script::GetLineNumber(script, pos_) + 1; return Script::GetLineNumber(script, pos_) + 1;
...@@ -246,9 +259,9 @@ int CallSite::GetLineNumber(Isolate* isolate) { ...@@ -246,9 +259,9 @@ int CallSite::GetLineNumber(Isolate* isolate) {
} }
int CallSite::GetColumnNumber(Isolate* isolate) { int CallSite::GetColumnNumber() {
if (pos_ >= 0) { if (pos_ >= 0) {
Handle<Object> script_obj(fun_->shared()->script(), isolate); Handle<Object> script_obj(fun_->shared()->script(), isolate_);
if (script_obj->IsScript()) { if (script_obj->IsScript()) {
Handle<Script> script = Handle<Script>::cast(script_obj); Handle<Script> script = Handle<Script>::cast(script_obj);
return Script::GetColumnNumber(script, pos_) + 1; return Script::GetColumnNumber(script, pos_) + 1;
...@@ -258,32 +271,32 @@ int CallSite::GetColumnNumber(Isolate* isolate) { ...@@ -258,32 +271,32 @@ int CallSite::GetColumnNumber(Isolate* isolate) {
} }
bool CallSite::IsNative(Isolate* isolate) { bool CallSite::IsNative() {
Handle<Object> script(fun_->shared()->script(), isolate); Handle<Object> script(fun_->shared()->script(), isolate_);
return script->IsScript() && return script->IsScript() &&
Handle<Script>::cast(script)->type()->value() == Script::TYPE_NATIVE; Handle<Script>::cast(script)->type()->value() == Script::TYPE_NATIVE;
} }
bool CallSite::IsToplevel(Isolate* isolate) { bool CallSite::IsToplevel() {
return receiver_->IsJSGlobalProxy() || receiver_->IsNull() || return receiver_->IsJSGlobalProxy() || receiver_->IsNull() ||
receiver_->IsUndefined(); receiver_->IsUndefined();
} }
bool CallSite::IsEval(Isolate* isolate) { bool CallSite::IsEval() {
Handle<Object> script(fun_->shared()->script(), isolate); Handle<Object> script(fun_->shared()->script(), isolate_);
return script->IsScript() && return script->IsScript() &&
Handle<Script>::cast(script)->compilation_type() == Handle<Script>::cast(script)->compilation_type() ==
Script::COMPILATION_TYPE_EVAL; Script::COMPILATION_TYPE_EVAL;
} }
bool CallSite::IsConstructor(Isolate* isolate) { bool CallSite::IsConstructor() {
if (!receiver_->IsJSObject()) return false; if (!receiver_->IsJSObject()) return false;
Handle<Object> constructor = Handle<Object> constructor =
JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_), JSReceiver::GetDataProperty(Handle<JSObject>::cast(receiver_),
isolate->factory()->constructor_string()); isolate_->factory()->constructor_string());
return constructor.is_identical_to(fun_); return constructor.is_identical_to(fun_);
} }
......
...@@ -47,23 +47,23 @@ class MessageLocation { ...@@ -47,23 +47,23 @@ class MessageLocation {
class CallSite { class CallSite {
public: public:
CallSite(Handle<Object> receiver, Handle<JSFunction> fun, int pos) CallSite(Isolate* isolate, Handle<JSObject> call_site_obj);
: receiver_(receiver), fun_(fun), pos_(pos) {}
Handle<Object> GetFileName(Isolate* isolate); Handle<Object> GetFileName();
Handle<Object> GetFunctionName(Isolate* isolate); Handle<Object> GetFunctionName();
Handle<Object> GetScriptNameOrSourceUrl(Isolate* isolate); Handle<Object> GetScriptNameOrSourceUrl();
Handle<Object> GetMethodName(Isolate* isolate); Handle<Object> GetMethodName();
// Return 1-based line number, including line offset. // Return 1-based line number, including line offset.
int GetLineNumber(Isolate* isolate); int GetLineNumber();
// Return 1-based column number, including column offset if first line. // Return 1-based column number, including column offset if first line.
int GetColumnNumber(Isolate* isolate); int GetColumnNumber();
bool IsNative(Isolate* isolate); bool IsNative();
bool IsToplevel(Isolate* isolate); bool IsToplevel();
bool IsEval(Isolate* isolate); bool IsEval();
bool IsConstructor(Isolate* isolate); bool IsConstructor();
private: private:
Isolate* isolate_;
Handle<Object> receiver_; Handle<Object> receiver_;
Handle<JSFunction> fun_; Handle<JSFunction> fun_;
int pos_; int pos_;
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
// ------------------------------------------------------------------- // -------------------------------------------------------------------
var $errorToString; var $errorToString;
var $internalErrorSymbol;
var $stackTraceSymbol;
var MakeError; var MakeError;
var MakeEvalError; var MakeEvalError;
var MakeRangeError; var MakeRangeError;
...@@ -26,15 +24,26 @@ var ArrayJoin; ...@@ -26,15 +24,26 @@ var ArrayJoin;
var Bool16x8ToString; var Bool16x8ToString;
var Bool32x4ToString; var Bool32x4ToString;
var Bool8x16ToString; var Bool8x16ToString;
var callSiteReceiverSymbol =
utils.GetPrivateSymbol("call_site_receiver_symbol");
var callSiteFunctionSymbol =
utils.GetPrivateSymbol("call_site_function_symbol");
var callSitePositionSymbol =
utils.GetPrivateSymbol("call_site_position_symbol");
var callSiteStrictSymbol = utils.GetPrivateSymbol("call_site_strict_symbol");
var Float32x4ToString; var Float32x4ToString;
var formattedStackTraceSymbol =
utils.GetPrivateSymbol("formatted_stack_trace_symbol");
var FunctionSourceString var FunctionSourceString
var GlobalObject = global.Object; var GlobalObject = global.Object;
var Int16x8ToString; var Int16x8ToString;
var Int32x4ToString; var Int32x4ToString;
var Int8x16ToString; var Int8x16ToString;
var InternalArray = utils.InternalArray; var InternalArray = utils.InternalArray;
var internalErrorSymbol = utils.GetPrivateSymbol("internal_error_symbol");
var ObjectDefineProperty; var ObjectDefineProperty;
var ObjectToString; var ObjectToString;
var stackTraceSymbol = utils.GetPrivateSymbol("stack_trace_symbol");
var StringCharAt; var StringCharAt;
var StringIndexOf; var StringIndexOf;
var StringSubstring; var StringSubstring;
...@@ -173,7 +182,7 @@ function ToDetailString(obj) { ...@@ -173,7 +182,7 @@ function ToDetailString(obj) {
function MakeGenericError(constructor, type, arg0, arg1, arg2) { function MakeGenericError(constructor, type, arg0, arg1, arg2) {
var error = new constructor(FormatMessage(type, arg0, arg1, arg2)); var error = new constructor(FormatMessage(type, arg0, arg1, arg2));
error[$internalErrorSymbol] = true; error[internalErrorSymbol] = true;
return error; return error;
} }
...@@ -574,112 +583,77 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) { ...@@ -574,112 +583,77 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Error implementation // Error implementation
var CallSiteReceiverKey = NEW_PRIVATE("CallSite#receiver");
var CallSiteFunctionKey = NEW_PRIVATE("CallSite#function");
var CallSitePositionKey = NEW_PRIVATE("CallSite#position");
var CallSiteStrictModeKey = NEW_PRIVATE("CallSite#strict_mode");
function CallSite(receiver, fun, pos, strict_mode) { function CallSite(receiver, fun, pos, strict_mode) {
SET_PRIVATE(this, CallSiteReceiverKey, receiver); SET_PRIVATE(this, callSiteReceiverSymbol, receiver);
SET_PRIVATE(this, CallSiteFunctionKey, fun); SET_PRIVATE(this, callSiteFunctionSymbol, fun);
SET_PRIVATE(this, CallSitePositionKey, pos); SET_PRIVATE(this, callSitePositionSymbol, pos);
SET_PRIVATE(this, CallSiteStrictModeKey, strict_mode); SET_PRIVATE(this, callSiteStrictSymbol, strict_mode);
} }
function CallSiteGetThis() { function CallSiteGetThis() {
return GET_PRIVATE(this, CallSiteStrictModeKey) return GET_PRIVATE(this, callSiteStrictSymbol)
? UNDEFINED : GET_PRIVATE(this, CallSiteReceiverKey); ? UNDEFINED : GET_PRIVATE(this, callSiteReceiverSymbol);
} }
function CallSiteGetFunction() { function CallSiteGetFunction() {
return GET_PRIVATE(this, CallSiteStrictModeKey) return GET_PRIVATE(this, callSiteStrictSymbol)
? UNDEFINED : GET_PRIVATE(this, CallSiteFunctionKey); ? UNDEFINED : GET_PRIVATE(this, callSiteFunctionSymbol);
} }
function CallSiteGetPosition() { function CallSiteGetPosition() {
return GET_PRIVATE(this, CallSitePositionKey); return GET_PRIVATE(this, callSitePositionSymbol);
} }
function CallSiteGetTypeName() { function CallSiteGetTypeName() {
return GetTypeName(GET_PRIVATE(this, CallSiteReceiverKey), false); return GetTypeName(GET_PRIVATE(this, callSiteReceiverSymbol), false);
} }
function CallSiteIsToplevel() { function CallSiteIsToplevel() {
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteIsToplevelRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteIsToplevelRT(receiver, fun, pos);
} }
function CallSiteIsEval() { function CallSiteIsEval() {
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteIsEvalRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteIsEvalRT(receiver, fun, pos);
} }
function CallSiteGetEvalOrigin() { function CallSiteGetEvalOrigin() {
var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); var script = %FunctionGetScript(GET_PRIVATE(this, callSiteFunctionSymbol));
return FormatEvalOrigin(script); return FormatEvalOrigin(script);
} }
function CallSiteGetScriptNameOrSourceURL() { function CallSiteGetScriptNameOrSourceURL() {
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteGetScriptNameOrSourceUrlRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteGetScriptNameOrSourceUrlRT(receiver, fun, pos);
} }
function CallSiteGetFunctionName() { function CallSiteGetFunctionName() {
// See if the function knows its own name // See if the function knows its own name
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteGetFunctionNameRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteGetFunctionNameRT(receiver, fun, pos);
} }
function CallSiteGetMethodName() { function CallSiteGetMethodName() {
// See if we can find a unique property on the receiver that holds // See if we can find a unique property on the receiver that holds
// this function. // this function.
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteGetMethodNameRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteGetMethodNameRT(receiver, fun, pos);
} }
function CallSiteGetFileName() { function CallSiteGetFileName() {
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteGetFileNameRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteGetFileNameRT(receiver, fun, pos);
} }
function CallSiteGetLineNumber() { function CallSiteGetLineNumber() {
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteGetLineNumberRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteGetLineNumberRT(receiver, fun, pos);
} }
function CallSiteGetColumnNumber() { function CallSiteGetColumnNumber() {
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteGetColumnNumberRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteGetColumnNumberRT(receiver, fun, pos);
} }
function CallSiteIsNative() { function CallSiteIsNative() {
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteIsNativeRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteIsNativeRT(receiver, fun, pos);
} }
function CallSiteIsConstructor() { function CallSiteIsConstructor() {
var receiver = GET_PRIVATE(this, CallSiteReceiverKey); return %CallSiteIsConstructorRT(this);
var fun = GET_PRIVATE(this, CallSiteFunctionKey);
var pos = GET_PRIVATE(this, CallSitePositionKey);
return %CallSiteIsConstructorRT(receiver, fun, pos);
} }
function CallSiteToString() { function CallSiteToString() {
...@@ -718,7 +692,7 @@ function CallSiteToString() { ...@@ -718,7 +692,7 @@ function CallSiteToString() {
var isConstructor = this.isConstructor(); var isConstructor = this.isConstructor();
var isMethodCall = !(this.isToplevel() || isConstructor); var isMethodCall = !(this.isToplevel() || isConstructor);
if (isMethodCall) { if (isMethodCall) {
var typeName = GetTypeName(GET_PRIVATE(this, CallSiteReceiverKey), true); var typeName = GetTypeName(GET_PRIVATE(this, callSiteReceiverSymbol), true);
var methodName = this.getMethodName(); var methodName = this.getMethodName();
if (functionName) { if (functionName) {
if (typeName && if (typeName &&
...@@ -894,8 +868,6 @@ function GetTypeName(receiver, requireConstructor) { ...@@ -894,8 +868,6 @@ function GetTypeName(receiver, requireConstructor) {
return constructorName; return constructorName;
} }
var formatted_stack_trace_symbol = NEW_PRIVATE("formatted stack trace");
// Format the stack trace if not yet done, and return it. // Format the stack trace if not yet done, and return it.
// Cache the formatted stack trace on the holder. // Cache the formatted stack trace on the holder.
...@@ -904,10 +876,10 @@ var StackTraceGetter = function() { ...@@ -904,10 +876,10 @@ var StackTraceGetter = function() {
var holder = this; var holder = this;
while (holder) { while (holder) {
var formatted_stack_trace = var formatted_stack_trace =
GET_PRIVATE(holder, formatted_stack_trace_symbol); GET_PRIVATE(holder, formattedStackTraceSymbol);
if (IS_UNDEFINED(formatted_stack_trace)) { if (IS_UNDEFINED(formatted_stack_trace)) {
// No formatted stack trace available. // No formatted stack trace available.
var stack_trace = GET_PRIVATE(holder, $stackTraceSymbol); var stack_trace = GET_PRIVATE(holder, stackTraceSymbol);
if (IS_UNDEFINED(stack_trace)) { if (IS_UNDEFINED(stack_trace)) {
// Neither formatted nor structured stack trace available. // Neither formatted nor structured stack trace available.
// Look further up the prototype chain. // Look further up the prototype chain.
...@@ -915,8 +887,8 @@ var StackTraceGetter = function() { ...@@ -915,8 +887,8 @@ var StackTraceGetter = function() {
continue; continue;
} }
formatted_stack_trace = FormatStackTrace(holder, stack_trace); formatted_stack_trace = FormatStackTrace(holder, stack_trace);
SET_PRIVATE(holder, $stackTraceSymbol, UNDEFINED); SET_PRIVATE(holder, stackTraceSymbol, UNDEFINED);
SET_PRIVATE(holder, formatted_stack_trace_symbol, formatted_stack_trace); SET_PRIVATE(holder, formattedStackTraceSymbol, formatted_stack_trace);
} }
return formatted_stack_trace; return formatted_stack_trace;
} }
...@@ -927,9 +899,9 @@ var StackTraceGetter = function() { ...@@ -927,9 +899,9 @@ var StackTraceGetter = function() {
// If the receiver equals the holder, set the formatted stack trace that the // If the receiver equals the holder, set the formatted stack trace that the
// getter returns. // getter returns.
var StackTraceSetter = function(v) { var StackTraceSetter = function(v) {
if (HAS_PRIVATE(this, $stackTraceSymbol)) { if (HAS_PRIVATE(this, stackTraceSymbol)) {
SET_PRIVATE(this, $stackTraceSymbol, UNDEFINED); SET_PRIVATE(this, stackTraceSymbol, UNDEFINED);
SET_PRIVATE(this, formatted_stack_trace_symbol, v); SET_PRIVATE(this, formattedStackTraceSymbol, v);
} }
}; };
......
...@@ -139,7 +139,7 @@ bool Object::IsPromise(Handle<Object> object) { ...@@ -139,7 +139,7 @@ bool Object::IsPromise(Handle<Object> object) {
auto isolate = js_object->GetIsolate(); auto isolate = js_object->GetIsolate();
// TODO(dcarney): this should just be read from the symbol registry so as not // TODO(dcarney): this should just be read from the symbol registry so as not
// to be context dependent. // to be context dependent.
auto key = isolate->promise_status(); auto key = isolate->factory()->promise_status_symbol();
// Shouldn't be possible to throw here. // Shouldn't be possible to throw here.
return JSObject::HasRealNamedProperty(js_object, key).FromJust(); return JSObject::HasRealNamedProperty(js_object, key).FromJust();
} }
......
...@@ -156,6 +156,13 @@ function SetUpLockedPrototype( ...@@ -156,6 +156,13 @@ function SetUpLockedPrototype(
%ToFastProperties(prototype); %ToFastProperties(prototype);
} }
var private_symbols = %ExportPrivateSymbols({});
function GetPrivateSymbol(name) {
return private_symbols[name];
}
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// To be called by bootstrapper // To be called by bootstrapper
...@@ -236,6 +243,7 @@ function PostExperimentals(utils) { ...@@ -236,6 +243,7 @@ function PostExperimentals(utils) {
%ImportExperimentalToRuntime(runtime_container); %ImportExperimentalToRuntime(runtime_container);
exports_container = UNDEFINED; exports_container = UNDEFINED;
private_symbols = UNDEFINED;
utils.PostExperimentals = UNDEFINED; utils.PostExperimentals = UNDEFINED;
utils.PostDebug = UNDEFINED; utils.PostDebug = UNDEFINED;
...@@ -250,6 +258,7 @@ function PostDebug(utils) { ...@@ -250,6 +258,7 @@ function PostDebug(utils) {
} }
exports_container = UNDEFINED; exports_container = UNDEFINED;
private_symbols = UNDEFINED;
utils.PostDebug = UNDEFINED; utils.PostDebug = UNDEFINED;
utils.PostExperimentals = UNDEFINED; utils.PostExperimentals = UNDEFINED;
...@@ -259,13 +268,14 @@ function PostDebug(utils) { ...@@ -259,13 +268,14 @@ function PostDebug(utils) {
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
%OptimizeObjectForAddingMultipleProperties(utils, 14); %OptimizeObjectForAddingMultipleProperties(utils, 15);
utils.Import = Import; utils.Import = Import;
utils.ImportNow = ImportNow; utils.ImportNow = ImportNow;
utils.Export = Export; utils.Export = Export;
utils.ExportToRuntime = ExportToRuntime; utils.ExportToRuntime = ExportToRuntime;
utils.ImportFromExperimental = ImportFromExperimental; utils.ImportFromExperimental = ImportFromExperimental;
utils.GetPrivateSymbol = GetPrivateSymbol;
utils.SetFunctionName = SetFunctionName; utils.SetFunctionName = SetFunctionName;
utils.InstallConstants = InstallConstants; utils.InstallConstants = InstallConstants;
utils.InstallFunctions = InstallFunctions; utils.InstallFunctions = InstallFunctions;
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var $promiseHasUserDefinedRejectHandler;
var $promiseStatus;
var $promiseValue;
(function(global, utils) { (function(global, utils) {
"use strict"; "use strict";
...@@ -16,20 +12,22 @@ var $promiseValue; ...@@ -16,20 +12,22 @@ var $promiseValue;
// Imports // Imports
var InternalArray = utils.InternalArray; var InternalArray = utils.InternalArray;
var promiseHasHandlerSymbol =
utils.GetPrivateSymbol("promise_has_handler_symbol");
var promiseOnRejectSymbol = utils.GetPrivateSymbol("promise_on_reject_symbol");
var promiseOnResolveSymbol =
utils.GetPrivateSymbol("promise_on_resolve_symbol");
var promiseRawSymbol = utils.GetPrivateSymbol("promise_raw_symbol");
var promiseStatusSymbol = utils.GetPrivateSymbol("promise_status_symbol");
var promiseValueSymbol = utils.GetPrivateSymbol("promise_value_symbol");
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Status values: 0 = pending, +1 = resolved, -1 = rejected // Status values: 0 = pending, +1 = resolved, -1 = rejected
var promiseStatus = GLOBAL_PRIVATE("Promise#status");
var promiseValue = GLOBAL_PRIVATE("Promise#value");
var promiseOnResolve = GLOBAL_PRIVATE("Promise#onResolve");
var promiseOnReject = GLOBAL_PRIVATE("Promise#onReject");
var promiseRaw = GLOBAL_PRIVATE("Promise#raw");
var promiseHasHandler = %PromiseHasHandlerSymbol();
var lastMicrotaskId = 0; var lastMicrotaskId = 0;
var GlobalPromise = function Promise(resolver) { var GlobalPromise = function Promise(resolver) {
if (resolver === promiseRaw) return; if (resolver === promiseRawSymbol) return;
if (!%_IsConstructCall()) throw MakeTypeError(kNotAPromise, this); if (!%_IsConstructCall()) throw MakeTypeError(kNotAPromise, this);
if (!IS_SPEC_FUNCTION(resolver)) if (!IS_SPEC_FUNCTION(resolver))
throw MakeTypeError(kResolverNotAFunction, resolver); throw MakeTypeError(kResolverNotAFunction, resolver);
...@@ -48,10 +46,10 @@ var GlobalPromise = function Promise(resolver) { ...@@ -48,10 +46,10 @@ var GlobalPromise = function Promise(resolver) {
// Core functionality. // Core functionality.
function PromiseSet(promise, status, value, onResolve, onReject) { function PromiseSet(promise, status, value, onResolve, onReject) {
SET_PRIVATE(promise, promiseStatus, status); SET_PRIVATE(promise, promiseStatusSymbol, status);
SET_PRIVATE(promise, promiseValue, value); SET_PRIVATE(promise, promiseValueSymbol, value);
SET_PRIVATE(promise, promiseOnResolve, onResolve); SET_PRIVATE(promise, promiseOnResolveSymbol, onResolve);
SET_PRIVATE(promise, promiseOnReject, onReject); SET_PRIVATE(promise, promiseOnRejectSymbol, onReject);
if (DEBUG_IS_ACTIVE) { if (DEBUG_IS_ACTIVE) {
%DebugPromiseEvent({ promise: promise, status: status, value: value }); %DebugPromiseEvent({ promise: promise, status: status, value: value });
} }
...@@ -59,7 +57,7 @@ function PromiseSet(promise, status, value, onResolve, onReject) { ...@@ -59,7 +57,7 @@ function PromiseSet(promise, status, value, onResolve, onReject) {
} }
function PromiseCreateAndSet(status, value) { function PromiseCreateAndSet(status, value) {
var promise = new GlobalPromise(promiseRaw); var promise = new GlobalPromise(promiseRawSymbol);
// If debug is active, notify about the newly created promise first. // If debug is active, notify about the newly created promise first.
if (DEBUG_IS_ACTIVE) PromiseSet(promise, 0, UNDEFINED); if (DEBUG_IS_ACTIVE) PromiseSet(promise, 0, UNDEFINED);
return PromiseSet(promise, status, value); return PromiseSet(promise, status, value);
...@@ -71,7 +69,7 @@ function PromiseInit(promise) { ...@@ -71,7 +69,7 @@ function PromiseInit(promise) {
} }
function PromiseDone(promise, status, value, promiseQueue) { function PromiseDone(promise, status, value, promiseQueue) {
if (GET_PRIVATE(promise, promiseStatus) === 0) { if (GET_PRIVATE(promise, promiseStatusSymbol) === 0) {
var tasks = GET_PRIVATE(promise, promiseQueue); var tasks = GET_PRIVATE(promise, promiseQueue);
if (tasks.length) PromiseEnqueue(value, tasks, status); if (tasks.length) PromiseEnqueue(value, tasks, status);
PromiseSet(promise, status, value); PromiseSet(promise, status, value);
...@@ -148,7 +146,7 @@ function PromiseNopResolver() {} ...@@ -148,7 +146,7 @@ function PromiseNopResolver() {}
// For bootstrapper. // For bootstrapper.
function IsPromise(x) { function IsPromise(x) {
return IS_SPEC_OBJECT(x) && HAS_DEFINED_PRIVATE(x, promiseStatus); return IS_SPEC_OBJECT(x) && HAS_DEFINED_PRIVATE(x, promiseStatusSymbol);
} }
function PromiseCreate() { function PromiseCreate() {
...@@ -156,19 +154,20 @@ function PromiseCreate() { ...@@ -156,19 +154,20 @@ function PromiseCreate() {
} }
function PromiseResolve(promise, x) { function PromiseResolve(promise, x) {
PromiseDone(promise, +1, x, promiseOnResolve) PromiseDone(promise, +1, x, promiseOnResolveSymbol)
} }
function PromiseReject(promise, r) { function PromiseReject(promise, r) {
// Check promise status to confirm that this reject has an effect. // Check promise status to confirm that this reject has an effect.
// Call runtime for callbacks to the debugger or for unhandled reject. // Call runtime for callbacks to the debugger or for unhandled reject.
if (GET_PRIVATE(promise, promiseStatus) == 0) { if (GET_PRIVATE(promise, promiseStatusSymbol) == 0) {
var debug_is_active = DEBUG_IS_ACTIVE; var debug_is_active = DEBUG_IS_ACTIVE;
if (debug_is_active || !HAS_DEFINED_PRIVATE(promise, promiseHasHandler)) { if (debug_is_active ||
!HAS_DEFINED_PRIVATE(promise, promiseHasHandlerSymbol)) {
%PromiseRejectEvent(promise, r, debug_is_active); %PromiseRejectEvent(promise, r, debug_is_active);
} }
} }
PromiseDone(promise, -1, r, promiseOnReject) PromiseDone(promise, -1, r, promiseOnRejectSymbol)
} }
// Convenience. // Convenience.
...@@ -176,7 +175,7 @@ function PromiseReject(promise, r) { ...@@ -176,7 +175,7 @@ function PromiseReject(promise, r) {
function PromiseDeferred() { function PromiseDeferred() {
if (this === GlobalPromise) { if (this === GlobalPromise) {
// Optimized case, avoid extra closure. // Optimized case, avoid extra closure.
var promise = PromiseInit(new GlobalPromise(promiseRaw)); var promise = PromiseInit(new GlobalPromise(promiseRawSymbol));
return { return {
promise: promise, promise: promise,
resolve: function(x) { PromiseResolve(promise, x) }, resolve: function(x) { PromiseResolve(promise, x) },
...@@ -221,31 +220,31 @@ function PromiseChain(onResolve, onReject) { // a.k.a. flatMap ...@@ -221,31 +220,31 @@ function PromiseChain(onResolve, onReject) { // a.k.a. flatMap
onResolve = IS_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve; onResolve = IS_UNDEFINED(onResolve) ? PromiseIdResolveHandler : onResolve;
onReject = IS_UNDEFINED(onReject) ? PromiseIdRejectHandler : onReject; onReject = IS_UNDEFINED(onReject) ? PromiseIdRejectHandler : onReject;
var deferred = %_CallFunction(this.constructor, PromiseDeferred); var deferred = %_CallFunction(this.constructor, PromiseDeferred);
switch (GET_PRIVATE(this, promiseStatus)) { switch (GET_PRIVATE(this, promiseStatusSymbol)) {
case UNDEFINED: case UNDEFINED:
throw MakeTypeError(kNotAPromise, this); throw MakeTypeError(kNotAPromise, this);
case 0: // Pending case 0: // Pending
GET_PRIVATE(this, promiseOnResolve).push(onResolve, deferred); GET_PRIVATE(this, promiseOnResolveSymbol).push(onResolve, deferred);
GET_PRIVATE(this, promiseOnReject).push(onReject, deferred); GET_PRIVATE(this, promiseOnRejectSymbol).push(onReject, deferred);
break; break;
case +1: // Resolved case +1: // Resolved
PromiseEnqueue(GET_PRIVATE(this, promiseValue), PromiseEnqueue(GET_PRIVATE(this, promiseValueSymbol),
[onResolve, deferred], [onResolve, deferred],
+1); +1);
break; break;
case -1: // Rejected case -1: // Rejected
if (!HAS_DEFINED_PRIVATE(this, promiseHasHandler)) { if (!HAS_DEFINED_PRIVATE(this, promiseHasHandlerSymbol)) {
// Promise has already been rejected, but had no handler. // Promise has already been rejected, but had no handler.
// Revoke previously triggered reject event. // Revoke previously triggered reject event.
%PromiseRevokeReject(this); %PromiseRevokeReject(this);
} }
PromiseEnqueue(GET_PRIVATE(this, promiseValue), PromiseEnqueue(GET_PRIVATE(this, promiseValueSymbol),
[onReject, deferred], [onReject, deferred],
-1); -1);
break; break;
} }
// Mark this promise as having handler. // Mark this promise as having handler.
SET_PRIVATE(this, promiseHasHandler, true); SET_PRIVATE(this, promiseHasHandlerSymbol, true);
if (DEBUG_IS_ACTIVE) { if (DEBUG_IS_ACTIVE) {
%DebugPromiseEvent({ promise: deferred.promise, parentPromise: this }); %DebugPromiseEvent({ promise: deferred.promise, parentPromise: this });
} }
...@@ -340,7 +339,7 @@ function PromiseRace(iterable) { ...@@ -340,7 +339,7 @@ function PromiseRace(iterable) {
// Utility for debugger // Utility for debugger
function PromiseHasUserDefinedRejectHandlerRecursive(promise) { function PromiseHasUserDefinedRejectHandlerRecursive(promise) {
var queue = GET_PRIVATE(promise, promiseOnReject); var queue = GET_PRIVATE(promise, promiseOnRejectSymbol);
if (IS_UNDEFINED(queue)) return false; if (IS_UNDEFINED(queue)) return false;
for (var i = 0; i < queue.length; i += 2) { for (var i = 0; i < queue.length; i += 2) {
if (queue[i] != PromiseIdRejectHandler) return true; if (queue[i] != PromiseIdRejectHandler) return true;
...@@ -380,12 +379,7 @@ utils.InstallFunctions(GlobalPromise.prototype, DONT_ENUM, [ ...@@ -380,12 +379,7 @@ utils.InstallFunctions(GlobalPromise.prototype, DONT_ENUM, [
"catch", PromiseCatch "catch", PromiseCatch
]); ]);
$promiseStatus = promiseStatus;
$promiseValue = promiseValue;
utils.ExportToRuntime(function(to) { utils.ExportToRuntime(function(to) {
to.promiseStatus = promiseStatus;
to.promiseValue = promiseValue;
to.PromiseCreate = PromiseCreate; to.PromiseCreate = PromiseCreate;
to.PromiseResolve = PromiseResolve; to.PromiseResolve = PromiseResolve;
to.PromiseReject = PromiseReject; to.PromiseReject = PromiseReject;
......
...@@ -221,7 +221,7 @@ MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate, ...@@ -221,7 +221,7 @@ MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate,
Handle<JSObject> promise = Handle<JSObject>::cast(object); Handle<JSObject> promise = Handle<JSObject>::cast(object);
Handle<Object> status_obj = Handle<Object> status_obj =
DebugGetProperty(promise, isolate->promise_status()); DebugGetProperty(promise, isolate->factory()->promise_status_symbol());
RUNTIME_ASSERT_HANDLIFIED(status_obj->IsSmi(), JSArray); RUNTIME_ASSERT_HANDLIFIED(status_obj->IsSmi(), JSArray);
const char* status = "rejected"; const char* status = "rejected";
int status_val = Handle<Smi>::cast(status_obj)->value(); int status_val = Handle<Smi>::cast(status_obj)->value();
...@@ -244,7 +244,7 @@ MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate, ...@@ -244,7 +244,7 @@ MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate,
result->set(1, *status_str); result->set(1, *status_str);
Handle<Object> value_obj = Handle<Object> value_obj =
DebugGetProperty(promise, isolate->promise_value()); DebugGetProperty(promise, isolate->factory()->promise_value_symbol());
Handle<String> promise_value = Handle<String> promise_value =
factory->NewStringFromAsciiChecked("[[PromiseValue]]"); factory->NewStringFromAsciiChecked("[[PromiseValue]]");
result->set(2, *promise_value); result->set(2, *promise_value);
......
...@@ -24,6 +24,19 @@ RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) { ...@@ -24,6 +24,19 @@ RUNTIME_FUNCTION(Runtime_CheckIsBootstrapping) {
} }
RUNTIME_FUNCTION(Runtime_ExportPrivateSymbols) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(JSObject, container, 0);
RUNTIME_ASSERT(isolate->bootstrapper()->IsActive());
JSObject::NormalizeProperties(container, KEEP_INOBJECT_PROPERTIES, 10,
"ExportPrivateSymbols");
Bootstrapper::ExportPrivateSymbols(isolate, container);
JSObject::MigrateSlowToFast(container, 0, "ExportPrivateSymbols");
return *container;
}
RUNTIME_FUNCTION(Runtime_ImportToRuntime) { RUNTIME_FUNCTION(Runtime_ImportToRuntime) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 1); DCHECK(args.length() == 1);
...@@ -172,12 +185,6 @@ RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { ...@@ -172,12 +185,6 @@ RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) {
} }
RUNTIME_FUNCTION(Runtime_PromiseHasHandlerSymbol) {
DCHECK(args.length() == 0);
return isolate->heap()->promise_has_handler_symbol();
}
RUNTIME_FUNCTION(Runtime_StackGuard) { RUNTIME_FUNCTION(Runtime_StackGuard) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
DCHECK(args.length() == 0); DCHECK(args.length() == 0);
...@@ -311,16 +318,14 @@ RUNTIME_FUNCTION(Runtime_FormatMessageString) { ...@@ -311,16 +318,14 @@ RUNTIME_FUNCTION(Runtime_FormatMessageString) {
} }
#define CALLSITE_GET(NAME, RETURN) \ #define CALLSITE_GET(NAME, RETURN) \
RUNTIME_FUNCTION(Runtime_CallSite##NAME##RT) { \ RUNTIME_FUNCTION(Runtime_CallSite##NAME##RT) { \
HandleScope scope(isolate); \ HandleScope scope(isolate); \
DCHECK(args.length() == 3); \ DCHECK(args.length() == 1); \
CONVERT_ARG_HANDLE_CHECKED(Object, receiver, 0); \ CONVERT_ARG_HANDLE_CHECKED(JSObject, call_site_obj, 0); \
CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 1); \ Handle<String> result; \
CONVERT_INT32_ARG_CHECKED(pos, 2); \ CallSite call_site(isolate, call_site_obj); \
Handle<String> result; \ return RETURN(call_site.NAME(), isolate); \
CallSite call_site(receiver, fun, pos); \
return RETURN(call_site.NAME(isolate), isolate); \
} }
static inline Object* ReturnDereferencedHandle(Handle<Object> obj, static inline Object* ReturnDereferencedHandle(Handle<Object> obj,
......
...@@ -30,27 +30,6 @@ RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) { ...@@ -30,27 +30,6 @@ RUNTIME_FUNCTION(Runtime_CreatePrivateSymbol) {
} }
RUNTIME_FUNCTION(Runtime_CreateGlobalPrivateSymbol) {
HandleScope scope(isolate);
DCHECK(args.length() == 1);
CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
Handle<JSObject> registry = isolate->GetSymbolRegistry();
Handle<String> part = isolate->factory()->private_intern_string();
Handle<Object> privates;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, privates,
Object::GetProperty(registry, part));
Handle<Object> symbol;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, symbol,
Object::GetProperty(privates, name));
if (!symbol->IsSymbol()) {
DCHECK(symbol->IsUndefined());
symbol = isolate->factory()->NewPrivateSymbol(name);
JSObject::AddProperty(Handle<JSObject>::cast(privates), name, symbol, NONE);
}
return *symbol;
}
RUNTIME_FUNCTION(Runtime_SymbolDescription) { RUNTIME_FUNCTION(Runtime_SymbolDescription) {
SealHandleScope shs(isolate); SealHandleScope shs(isolate);
DCHECK(args.length() == 1); DCHECK(args.length() == 1);
......
...@@ -302,6 +302,7 @@ namespace internal { ...@@ -302,6 +302,7 @@ namespace internal {
#define FOR_EACH_INTRINSIC_INTERNAL(F) \ #define FOR_EACH_INTRINSIC_INTERNAL(F) \
F(CheckIsBootstrapping, 0, 1) \ F(CheckIsBootstrapping, 0, 1) \
F(ExportPrivateSymbols, 1, 1) \
F(ImportToRuntime, 1, 1) \ F(ImportToRuntime, 1, 1) \
F(ImportExperimentalToRuntime, 1, 1) \ F(ImportExperimentalToRuntime, 1, 1) \
F(InstallJSBuiltins, 1, 1) \ F(InstallJSBuiltins, 1, 1) \
...@@ -317,7 +318,6 @@ namespace internal { ...@@ -317,7 +318,6 @@ namespace internal {
F(ThrowStrongModeImplicitConversion, 0, 1) \ F(ThrowStrongModeImplicitConversion, 0, 1) \
F(PromiseRejectEvent, 3, 1) \ F(PromiseRejectEvent, 3, 1) \
F(PromiseRevokeReject, 1, 1) \ F(PromiseRevokeReject, 1, 1) \
F(PromiseHasHandlerSymbol, 0, 1) \
F(StackGuard, 0, 1) \ F(StackGuard, 0, 1) \
F(Interrupt, 0, 1) \ F(Interrupt, 0, 1) \
F(AllocateInNewSpace, 1, 1) \ F(AllocateInNewSpace, 1, 1) \
...@@ -328,16 +328,16 @@ namespace internal { ...@@ -328,16 +328,16 @@ namespace internal {
F(MessageGetScript, 1, 1) \ F(MessageGetScript, 1, 1) \
F(ErrorToStringRT, 1, 1) \ F(ErrorToStringRT, 1, 1) \
F(FormatMessageString, 4, 1) \ F(FormatMessageString, 4, 1) \
F(CallSiteGetFileNameRT, 3, 1) \ F(CallSiteGetFileNameRT, 1, 1) \
F(CallSiteGetFunctionNameRT, 3, 1) \ F(CallSiteGetFunctionNameRT, 1, 1) \
F(CallSiteGetScriptNameOrSourceUrlRT, 3, 1) \ F(CallSiteGetScriptNameOrSourceUrlRT, 1, 1) \
F(CallSiteGetMethodNameRT, 3, 1) \ F(CallSiteGetMethodNameRT, 1, 1) \
F(CallSiteGetLineNumberRT, 3, 1) \ F(CallSiteGetLineNumberRT, 1, 1) \
F(CallSiteGetColumnNumberRT, 3, 1) \ F(CallSiteGetColumnNumberRT, 1, 1) \
F(CallSiteIsNativeRT, 3, 1) \ F(CallSiteIsNativeRT, 1, 1) \
F(CallSiteIsToplevelRT, 3, 1) \ F(CallSiteIsToplevelRT, 1, 1) \
F(CallSiteIsEvalRT, 3, 1) \ F(CallSiteIsEvalRT, 1, 1) \
F(CallSiteIsConstructorRT, 3, 1) \ F(CallSiteIsConstructorRT, 1, 1) \
F(IS_VAR, 1, 1) \ F(IS_VAR, 1, 1) \
F(IncrementStatsCounter, 1, 1) \ F(IncrementStatsCounter, 1, 1) \
F(Likely, 1, 1) \ F(Likely, 1, 1) \
...@@ -776,7 +776,6 @@ namespace internal { ...@@ -776,7 +776,6 @@ namespace internal {
#define FOR_EACH_INTRINSIC_SYMBOL(F) \ #define FOR_EACH_INTRINSIC_SYMBOL(F) \
F(CreateSymbol, 1, 1) \ F(CreateSymbol, 1, 1) \
F(CreatePrivateSymbol, 1, 1) \ F(CreatePrivateSymbol, 1, 1) \
F(CreateGlobalPrivateSymbol, 1, 1) \
F(SymbolDescription, 1, 1) \ F(SymbolDescription, 1, 1) \
F(SymbolRegistry, 0, 1) \ F(SymbolRegistry, 0, 1) \
F(SymbolIsPrivate, 1, 1) F(SymbolIsPrivate, 1, 1)
......
...@@ -11,9 +11,12 @@ ...@@ -11,9 +11,12 @@
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Imports // Imports
var GlobalString = global.String;
var ArrayIteratorCreateResultObject; var ArrayIteratorCreateResultObject;
var GlobalString = global.String;
var stringIteratorIteratedStringSymbol =
utils.GetPrivateSymbol("string_iterator_iterated_string_symbol");
var stringIteratorNextIndexSymbol =
utils.GetPrivateSymbol("string_iterator_next_index_symbol");
utils.Import(function(from) { utils.Import(function(from) {
ArrayIteratorCreateResultObject = from.ArrayIteratorCreateResultObject; ArrayIteratorCreateResultObject = from.ArrayIteratorCreateResultObject;
...@@ -21,11 +24,6 @@ utils.Import(function(from) { ...@@ -21,11 +24,6 @@ utils.Import(function(from) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
var stringIteratorIteratedStringSymbol =
GLOBAL_PRIVATE("StringIterator#iteratedString");
var stringIteratorNextIndexSymbol = GLOBAL_PRIVATE("StringIterator#next");
function StringIterator() {} function StringIterator() {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment