summaryrefslogtreecommitdiffstats
path: root/js/src/jsapi.cpp
diff options
context:
space:
mode:
authorwicknix <39230578+wicknix@users.noreply.github.com>2019-04-15 18:58:07 -0500
committerGitHub <noreply@github.com>2019-04-15 18:58:07 -0500
commit5a1843c9f9e323627f9c35529e6a8c853d4dbb0d (patch)
tree62de3cd7cb8a6f75e568863bb73ca2deb80d87a9 /js/src/jsapi.cpp
parent065f6f9e5ebc1ed6cfaadaf7851b6021fa94a013 (diff)
parent095ea556855b38138e39e713f482eb440f7da9b2 (diff)
downloadUXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.tar
UXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.tar.gz
UXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.tar.lz
UXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.tar.xz
UXP-5a1843c9f9e323627f9c35529e6a8c853d4dbb0d.zip
Merge pull request #1 from MoonchildProductions/master
keep up with mc
Diffstat (limited to 'js/src/jsapi.cpp')
-rw-r--r--js/src/jsapi.cpp67
1 files changed, 53 insertions, 14 deletions
diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp
index 85a38bba4..f78f94dc1 100644
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -2003,10 +2003,10 @@ JS_GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, const char* name,
}
JS_PUBLIC_API(bool)
-JS_GetOwnUCPropertyDescriptor(JSContext* cx, HandleObject obj, const char16_t* name,
+JS_GetOwnUCPropertyDescriptor(JSContext* cx, HandleObject obj, const char16_t* name, size_t namelen,
MutableHandle<PropertyDescriptor> desc)
{
- JSAtom* atom = AtomizeChars(cx, name, js_strlen(name));
+ JSAtom* atom = AtomizeChars(cx, name, namelen);
if (!atom)
return false;
RootedId id(cx, AtomToId(atom));
@@ -2028,7 +2028,19 @@ JS_GetPropertyDescriptor(JSContext* cx, HandleObject obj, const char* name,
if (!atom)
return false;
RootedId id(cx, AtomToId(atom));
- return atom && JS_GetPropertyDescriptorById(cx, obj, id, desc);
+ return JS_GetPropertyDescriptorById(cx, obj, id, desc);
+}
+
+JS_PUBLIC_API(bool)
+JS_GetUCPropertyDescriptor(JSContext* cx, HandleObject obj, const char16_t* name, size_t namelen,
+ MutableHandle<PropertyDescriptor> desc)
+{
+ JSAtom* atom = AtomizeChars(cx, name, namelen);
+ if (!atom) {
+ return false;
+ }
+ RootedId id(cx, AtomToId(atom));
+ return JS_GetPropertyDescriptorById(cx, obj, id, desc);
}
static bool
@@ -4238,7 +4250,7 @@ JS_GetFunctionScript(JSContext* cx, HandleFunction fun)
*/
static bool
CompileFunction(JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
- const char* name,
+ HandleAtom name, bool isInvalidName,
SourceBufferHolder& srcBuf, uint32_t parameterListEnd,
HandleObject enclosingEnv, HandleScope enclosingScope,
MutableHandleFunction fun)
@@ -4249,13 +4261,8 @@ CompileFunction(JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
assertSameCompartment(cx, enclosingEnv);
RootedAtom funAtom(cx);
- if (name) {
- funAtom = Atomize(cx, name, strlen(name));
- if (!funAtom)
- return false;
- }
-
- fun.set(NewScriptedFunction(cx, 0, JSFunction::INTERPRETED_NORMAL, funAtom,
+ fun.set(NewScriptedFunction(cx, 0, JSFunction::INTERPRETED_NORMAL,
+ isInvalidName ? nullptr : name,
/* proto = */ nullptr,
gc::AllocKind::FUNCTION, TenuredObject,
enclosingEnv));
@@ -4273,11 +4280,17 @@ CompileFunction(JSContext* cx, const ReadOnlyCompileOptions& optionsArg,
return false;
}
+ // When function name is not a valid identifier, the generated function
+ // source in srcBuf doesn't have a function name. Set it here.
+ if (isInvalidName)
+ fun->setAtom(name);
+
return true;
}
static MOZ_MUST_USE bool
-BuildFunctionString(unsigned nargs, const char* const* argnames,
+BuildFunctionString(const char* name, size_t nameLen,
+ unsigned nargs, const char* const* argnames,
const SourceBufferHolder& srcBuf, StringBuffer* out,
uint32_t* parameterListEnd)
{
@@ -4286,6 +4299,12 @@ BuildFunctionString(unsigned nargs, const char* const* argnames,
if (!out->ensureTwoByteChars())
return false;
+ if (!out->append("function "))
+ return false;
+ if (name) {
+ if (!out->append(name, nameLen))
+ return false;
+ }
if (!out->append("("))
return false;
for (unsigned i = 0; i < nargs; i++) {
@@ -4322,15 +4341,32 @@ JS::CompileFunction(JSContext* cx, AutoObjectVector& envChain,
if (!CreateNonSyntacticEnvironmentChain(cx, envChain, &env, &scope))
return false;
+ size_t nameLen = 0;
+ bool isInvalidName = false;
+ RootedAtom nameAtom(cx);
+ if (name) {
+ nameLen = strlen(name);
+ nameAtom = Atomize(cx, name, nameLen);
+ if (!nameAtom)
+ return false;
+
+ // If name is not valid identifier
+ if (!js::frontend::IsIdentifier(name, nameLen))
+ isInvalidName = true;
+ }
+
uint32_t parameterListEnd;
StringBuffer funStr(cx);
- if (!BuildFunctionString(nargs, argnames, srcBuf, &funStr, &parameterListEnd))
+ if (!BuildFunctionString(isInvalidName ? nullptr : name, nameLen, nargs, argnames, srcBuf,
+ &funStr, &parameterListEnd)) {
return false;
+ }
size_t newLen = funStr.length();
SourceBufferHolder newSrcBuf(funStr.stealChars(), newLen, SourceBufferHolder::GiveOwnership);
- return CompileFunction(cx, options, name, newSrcBuf, parameterListEnd, env, scope, fun);
+ return CompileFunction(cx, options, nameAtom, isInvalidName, newSrcBuf, parameterListEnd, env,
+ scope, fun);
}
JS_PUBLIC_API(bool)
@@ -6398,6 +6434,9 @@ JS_SetGlobalJitCompilerOption(JSContext* cx, JSJitCompilerOption opt, uint32_t v
}
jit::JitOptions.jumpThreshold = value;
break;
+ case JSJITCOMPILER_UNBOXED_OBJECTS:
+ jit::JitOptions.disableUnboxedObjects = !value;
+ break;
case JSJITCOMPILER_ASMJS_ATOMICS_ENABLE:
jit::JitOptions.asmJSAtomicsEnable = !!value;
break;