Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move RegExp properties to the prototype #14

Merged
merged 3 commits into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Runtime/Base/ThreadConfigFlagsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ FLAG_RELEASE(IsES6UnicodeExtensionsEnabled, ES6Unicode)
FLAG_RELEASE(IsES6UnscopablesEnabled, ES6Unscopables)
FLAG_RELEASE(IsES6WeakSetEnabled, ES6WeakSet)
FLAG_RELEASE(IsES6RegExStickyEnabled, ES6RegExSticky)
FLAG_RELEASE(IsES6RegExPrototypePropertiesEnabled, ES6RegExPrototypeProperties)
FLAG_RELEASE(IsES6HasInstanceEnabled, ES6HasInstance)
FLAG_RELEASE(SkipSplitOnNoResult, SkipSplitOnNoResult)
FLAG_RELEASE(IsES7AsyncAndAwaitEnabled, ES7AsyncAwait)
Expand Down
7 changes: 7 additions & 0 deletions lib/Runtime/Library/JavascriptBuiltInFunctionList.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ BUILTIN(JavascriptRegExp, Test, EntryTest, FunctionInfo::ErrorOnNew)
BUILTIN(JavascriptRegExp, ToString, EntryToString, FunctionInfo::ErrorOnNew | FunctionInfo::HasNoSideEffect)
BUILTIN(JavascriptRegExp, GetterSymbolSpecies, EntryGetterSymbolSpecies, FunctionInfo::ErrorOnNew)
BUILTIN(JavascriptRegExp, Compile, EntryCompile, FunctionInfo::None)
BUILTIN(JavascriptRegExp, GetterGlobal, EntryGetterGlobal, FunctionInfo::ErrorOnNew | FunctionInfo::HasNoSideEffect)
BUILTIN(JavascriptRegExp, GetterIgnoreCase, EntryGetterIgnoreCase, FunctionInfo::ErrorOnNew | FunctionInfo::HasNoSideEffect)
BUILTIN(JavascriptRegExp, GetterMultiline, EntryGetterMultiline, FunctionInfo::ErrorOnNew | FunctionInfo::HasNoSideEffect)
BUILTIN(JavascriptRegExp, GetterOptions, EntryGetterOptions, FunctionInfo::ErrorOnNew | FunctionInfo::HasNoSideEffect)
BUILTIN(JavascriptRegExp, GetterSource, EntryGetterSource, FunctionInfo::ErrorOnNew | FunctionInfo::HasNoSideEffect)
BUILTIN(JavascriptRegExp, GetterSticky, EntryGetterSticky, FunctionInfo::ErrorOnNew | FunctionInfo::HasNoSideEffect)
BUILTIN(JavascriptRegExp, GetterUnicode, EntryGetterUnicode, FunctionInfo::ErrorOnNew | FunctionInfo::HasNoSideEffect)
BUILTIN(JavascriptString, NewInstance, NewInstance, FunctionInfo::SkipDefaultNewObject)
BUILTIN(JavascriptString, CharAt, EntryCharAt, FunctionInfo::ErrorOnNew)
BUILTIN(JavascriptString, CharCodeAt, EntryCharCodeAt, FunctionInfo::ErrorOnNew)
Expand Down
36 changes: 31 additions & 5 deletions lib/Runtime/Library/JavascriptLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2534,24 +2534,30 @@ namespace Js

Recycler *const recycler = GetRecycler();

const ScriptConfiguration *scriptConfig = scriptContext->GetConfig();

// Creating the regex prototype object requires compiling an empty regex, which may require error types to be
// initialized first (such as when a stack probe fails). So, the regex prototype and other things that depend on it are
// initialized here, which will be after the dependency types are initialized.
//
// In ES6, RegExp.prototype is not a RegExp object itself so we do not need to wait and create an empty RegExp.
// Instead, we just create an ordinary object prototype for RegExp.prototype in InitializePrototypes.
if (!scriptContext->GetConfig()->IsES6PrototypeChain() && regexPrototype == nullptr)
if (!scriptConfig->IsES6PrototypeChain() && regexPrototype == nullptr)
{
regexPrototype = RecyclerNew(recycler, JavascriptRegExp, emptyRegexPattern,
DynamicType::New(scriptContext, TypeIds_RegEx, objectPrototype, nullptr,
DeferredTypeHandler<InitializeRegexPrototype>::GetDefaultInstance()));
}

regexType = DynamicType::New(scriptContext, TypeIds_RegEx, regexPrototype, nullptr,
SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true), true, true);
SimplePathTypeHandler *typeHandler =
SimplePathTypeHandler::New(scriptContext, scriptContext->GetRootPath(), 0, 0, 0, true, true);
// See JavascriptRegExp::IsWritable for property writability
if (!scriptConfig->IsES6RegExPrototypePropertiesEnabled())
{
typeHandler->ClearHasOnlyWritableDataProperties();
}

// See JavascriptRegExp::IsWritable for special non-writable properties
regexType->GetTypeHandler()->ClearHasOnlyWritableDataProperties();
regexType = DynamicType::New(scriptContext, TypeIds_RegEx, regexPrototype, nullptr, typeHandler, true, true);
}

void JavascriptLibrary::InitializeMathObject(DynamicObject* mathObject, DeferredTypeHandlerBase * typeHandler, DeferredInitializeMode mode)
Expand Down Expand Up @@ -3631,6 +3637,26 @@ namespace Js
// This is deprecated. Should be guarded with appropriate version flag.
library->AddFunctionToLibraryObject(regexPrototype, PropertyIds::compile, &JavascriptRegExp::EntryInfo::Compile, 2);

const ScriptConfiguration* scriptConfig = regexPrototype->GetScriptContext()->GetConfig();
if (scriptConfig->IsES6RegExPrototypePropertiesEnabled())
{
library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::global, &JavascriptRegExp::EntryInfo::GetterGlobal, nullptr);
library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::ignoreCase, &JavascriptRegExp::EntryInfo::GetterIgnoreCase, nullptr);
library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::multiline, &JavascriptRegExp::EntryInfo::GetterMultiline, nullptr);
library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::options, &JavascriptRegExp::EntryInfo::GetterOptions, nullptr);
library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::source, &JavascriptRegExp::EntryInfo::GetterSource, nullptr);

if (scriptConfig->IsES6RegExStickyEnabled())
{
library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::sticky, &JavascriptRegExp::EntryInfo::GetterSticky, nullptr);
}

if (scriptConfig->IsES6UnicodeExtensionsEnabled())
{
library->AddAccessorsToLibraryObject(regexPrototype, PropertyIds::unicode, &JavascriptRegExp::EntryInfo::GetterUnicode, nullptr);
}
}

DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, library->GetScriptContext()));

regexPrototype->SetHasNoEnumerableProperties(true);
Expand Down
Loading