Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use unsigned type for length of JSFunction
https://bugs.webkit.org/show_bug.cgi?id=215870

Reviewed by Darin Adler.

Since the `length` value of a built-in function is its arity,
we can communicate it's always non-negative via method signatures.

No behavior change: `length` values redefined by user code are unaffected.

* runtime/InternalFunction.cpp:
(JSC::InternalFunction::createFunctionThatMasqueradesAsUndefined):
* runtime/InternalFunction.h:
* runtime/JSFunction.cpp:
(JSC::JSFunction::create):
(JSC::JSFunction::finishCreation):
* runtime/JSFunction.h:
* runtime/JSNativeStdFunction.cpp:
(JSC::JSNativeStdFunction::finishCreation):
(JSC::JSNativeStdFunction::create):
* runtime/JSNativeStdFunction.h:


Canonical link: https://commits.webkit.org/228664@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266210 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
shvaikalesh committed Aug 27, 2020
1 parent e5ba28e commit 6e648a0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
24 changes: 24 additions & 0 deletions Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,27 @@
2020-08-26 Alexey Shvayka <shvaikalesh@gmail.com>

Use unsigned type for `length` of JSFunction
https://bugs.webkit.org/show_bug.cgi?id=215870

Reviewed by Darin Adler.

Since the `length` value of a built-in function is its arity,
we can communicate it's always non-negative via method signatures.

No behavior change: `length` values redefined by user code are unaffected.

* runtime/InternalFunction.cpp:
(JSC::InternalFunction::createFunctionThatMasqueradesAsUndefined):
* runtime/InternalFunction.h:
* runtime/JSFunction.cpp:
(JSC::JSFunction::create):
(JSC::JSFunction::finishCreation):
* runtime/JSFunction.h:
* runtime/JSNativeStdFunction.cpp:
(JSC::JSNativeStdFunction::finishCreation):
(JSC::JSNativeStdFunction::create):
* runtime/JSNativeStdFunction.h:

2020-08-26 Yusuke Suzuki <ysuzuki@apple.com>

[JSC] Enable Intl.Segmenter
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/InternalFunction.cpp
Expand Up @@ -154,7 +154,7 @@ Structure* InternalFunction::createSubclassStructure(JSGlobalObject* globalObjec
return baseClass;
}

InternalFunction* InternalFunction::createFunctionThatMasqueradesAsUndefined(VM& vm, JSGlobalObject* globalObject, int length, const String& name, NativeFunction nativeFunction)
InternalFunction* InternalFunction::createFunctionThatMasqueradesAsUndefined(VM& vm, JSGlobalObject* globalObject, unsigned length, const String& name, NativeFunction nativeFunction)
{
Structure* structure = Structure::create(vm, globalObject, globalObject->objectPrototype(), TypeInfo(InternalFunctionType, InternalFunction::StructureFlags | MasqueradesAsUndefined), InternalFunction::info());
globalObject->masqueradesAsUndefinedWatchpoint()->fireAll(globalObject->vm(), "Allocated masquerading object");
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/InternalFunction.h
Expand Up @@ -58,7 +58,7 @@ class InternalFunction : public JSNonFinalObject {
}

JS_EXPORT_PRIVATE static Structure* createSubclassStructure(JSGlobalObject*, JSObject* newTarget, Structure*);
JS_EXPORT_PRIVATE static InternalFunction* createFunctionThatMasqueradesAsUndefined(VM&, JSGlobalObject*, int length, const String& name, NativeFunction);
JS_EXPORT_PRIVATE static InternalFunction* createFunctionThatMasqueradesAsUndefined(VM&, JSGlobalObject*, unsigned length, const String& name, NativeFunction);

TaggedNativeFunction nativeFunctionFor(CodeSpecializationKind kind)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/runtime/JSFunction.cpp
Expand Up @@ -85,7 +85,7 @@ JSFunction* JSFunction::create(VM& vm, FunctionExecutable* executable, JSScope*
return result;
}

JSFunction* JSFunction::create(VM& vm, JSGlobalObject* globalObject, int length, const String& name, NativeFunction nativeFunction, Intrinsic intrinsic, NativeFunction nativeConstructor, const DOMJIT::Signature* signature)
JSFunction* JSFunction::create(VM& vm, JSGlobalObject* globalObject, unsigned length, const String& name, NativeFunction nativeFunction, Intrinsic intrinsic, NativeFunction nativeConstructor, const DOMJIT::Signature* signature)
{
NativeExecutable* executable = vm.getHostFunction(nativeFunction, intrinsic, nativeConstructor, signature, name);
Structure* structure = globalObject->hostFunctionStructure();
Expand Down Expand Up @@ -114,7 +114,7 @@ void JSFunction::finishCreation(VM& vm)
ASSERT(methodTable(vm)->getCallData == &JSFunction::getCallData);
}

void JSFunction::finishCreation(VM& vm, NativeExecutable*, int length, const String& name)
void JSFunction::finishCreation(VM& vm, NativeExecutable*, unsigned length, const String& name)
{
Base::finishCreation(vm);
ASSERT(inherits(vm, info()));
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/runtime/JSFunction.h
Expand Up @@ -80,7 +80,7 @@ class JSFunction : public JSCallee {

static Structure* selectStructureForNewFuncExp(JSGlobalObject*, FunctionExecutable*);

JS_EXPORT_PRIVATE static JSFunction* create(VM&, JSGlobalObject*, int length, const String& name, NativeFunction, Intrinsic = NoIntrinsic, NativeFunction nativeConstructor = callHostFunctionAsConstructor, const DOMJIT::Signature* = nullptr);
JS_EXPORT_PRIVATE static JSFunction* create(VM&, JSGlobalObject*, unsigned length, const String& name, NativeFunction, Intrinsic = NoIntrinsic, NativeFunction nativeConstructor = callHostFunctionAsConstructor, const DOMJIT::Signature* = nullptr);

static JSFunction* createWithInvalidatedReallocationWatchpoint(VM&, FunctionExecutable*, JSScope*);

Expand Down Expand Up @@ -169,7 +169,7 @@ class JSFunction : public JSCallee {
JS_EXPORT_PRIVATE JSFunction(VM&, NativeExecutable*, JSGlobalObject*, Structure*);
JSFunction(VM&, FunctionExecutable*, JSScope*, Structure*);

void finishCreation(VM&, NativeExecutable*, int length, const String& name);
void finishCreation(VM&, NativeExecutable*, unsigned length, const String& name);
void finishCreation(VM&);

static bool getOwnPropertySlot(JSObject*, JSGlobalObject*, PropertyName, PropertySlot&);
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/runtime/JSNativeStdFunction.cpp
Expand Up @@ -46,7 +46,7 @@ void JSNativeStdFunction::visitChildren(JSCell* cell, SlotVisitor& visitor)
Base::visitChildren(thisObject, visitor);
}

void JSNativeStdFunction::finishCreation(VM& vm, NativeExecutable* executable, int length, const String& name)
void JSNativeStdFunction::finishCreation(VM& vm, NativeExecutable* executable, unsigned length, const String& name)
{
Base::finishCreation(vm, executable, length, name);
ASSERT(inherits(vm, info()));
Expand All @@ -59,7 +59,7 @@ static EncodedJSValue JSC_HOST_CALL runStdFunction(JSGlobalObject* globalObject,
return function->function()(globalObject, callFrame);
}

JSNativeStdFunction* JSNativeStdFunction::create(VM& vm, JSGlobalObject* globalObject, int length, const String& name, NativeStdFunction&& nativeStdFunction, Intrinsic intrinsic, NativeFunction nativeConstructor)
JSNativeStdFunction* JSNativeStdFunction::create(VM& vm, JSGlobalObject* globalObject, unsigned length, const String& name, NativeStdFunction&& nativeStdFunction, Intrinsic intrinsic, NativeFunction nativeConstructor)
{
NativeExecutable* executable = vm.getHostFunction(runStdFunction, intrinsic, nativeConstructor, nullptr, name);
Structure* structure = globalObject->nativeStdFunctionStructure();
Expand Down
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/runtime/JSNativeStdFunction.h
Expand Up @@ -52,7 +52,7 @@ class JSNativeStdFunction final : public JSFunction {

DECLARE_EXPORT_INFO;

JS_EXPORT_PRIVATE static JSNativeStdFunction* create(VM&, JSGlobalObject*, int length, const String& name, NativeStdFunction&&, Intrinsic = NoIntrinsic, NativeFunction nativeConstructor = callHostFunctionAsConstructor);
JS_EXPORT_PRIVATE static JSNativeStdFunction* create(VM&, JSGlobalObject*, unsigned length, const String& name, NativeStdFunction&&, Intrinsic = NoIntrinsic, NativeFunction nativeConstructor = callHostFunctionAsConstructor);

static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
{
Expand All @@ -64,7 +64,7 @@ class JSNativeStdFunction final : public JSFunction {

private:
JSNativeStdFunction(VM&, NativeExecutable*, JSGlobalObject*, Structure*, NativeStdFunction&&);
void finishCreation(VM&, NativeExecutable*, int length, const String& name);
void finishCreation(VM&, NativeExecutable*, unsigned length, const String& name);
static void visitChildren(JSCell*, SlotVisitor&);

NativeStdFunction m_function;
Expand Down

0 comments on commit 6e648a0

Please sign in to comment.